我有類似的情況下,此問題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並選擇四個選項卡中的一個 –