我有一个类似的问题,与这个链接中的问题相同: iOS: apple universal link if app is not open? 当我点击通用链接时,如果应用程序不在后台,则无法进入
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {}
函数。 我在didFinishLaunchingWithOptions
中添加了一些代码。 但是它没有起作用。 如果有人能帮忙,非常感谢。func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let activityDic = launchOptions?[UIApplicationLaunchOptionsKey.userActivityDictionary]
if activityDic != nil {
// Continue activity here
self.window?.rootViewController?.restoreUserActivityState(activityDic as! NSUserActivity)
}
return true
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
if let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "xxx") as? XXXTableViewController {
if let window = self.window, let rootViewController = window.rootViewController {
var currentController = rootViewController
while let presentedController = currentController.presentedViewController {
currentController = presentedController
}
currentController.present(controller, animated: true, completion: nil)
}
}
}
return true
}
UIApplicationLaunchOptionsKey.url
什么情况下会不为空? - Will Calderwood