我有类似的情况下,此问题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
}
谢谢您的答复。我试过,但它说AppDelegate没有成员handleOpenURLWhenAppIsNotOpen。如果我输错了,我很抱歉。 – ray
handleOpenURLWhenAppIsNotOpen是我的自定义方法,您可以在其中编写您喜欢的任何内容(在应用程序中显示登录屏幕或其他屏幕)。在我的情况下,我初始化tabBarController并选择四个选项卡中的一个 –