提问人:鄭小火 提问时间:9/15/2023 更新时间:9/15/2023 访问量:43
在 Xcode 14 中将自定义 URL 方案数据从 AppDelegate 传递到 ViewController
Pass custom URL scheme data from AppDelegate to ViewController in Xcode 14
问:
自定义 URL 方案启动我的应用程序,这部分有效! 现在,我需要将自定义 URL 方案数据从 AppDelegate 传递给 ViewController 它总是一个空字符串,为什么?
在 AppDelegate 中:
var window: UIWindow?
var mytr: String!
func application(_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
mytr = "TheData" //just try a string first
return true
}
在 ViewController 中
override func viewDidLoad() {
super.viewDidLoad()
self.webView.uiDelegate = self
let appDelegate = UIApplication.shared.delegate as? AppDelegate
let mypath = appDelegate?.mytr //here mypath always be "" why?
答: 暂无答案
评论
viewDidLoad
open url
viewDidLoad
UIApplicationDelegate