在我的iOS应用中,我正在打开电子邮件中的链接。文件apple-app-site-association设置正确。为了处理链接,我在AppDelegate.swift中使用此功能:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL,
let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
return false
}
if (components.description.contains("/link1/")) {
let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewControlleripad : ViewNewPass = mainStoryboardIpad.instantiateViewController(withIdentifier: "NewPass") as! ViewNewPass
initialViewControlleripad.activationUrl = components.description
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = initialViewControlleripad
self.window?.makeKeyAndVisible()
return true
} else if (components.description.contains("/link2/")) {
let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewControlleripad : ViewController = mainStoryboardIpad.instantiateViewController(withIdentifier: "Login") as! ViewController
initialViewControlleripad.activationUrl = components.description
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = initialViewControlleripad
self.window?.makeKeyAndVisible()
return true
} else if (components.description.contains("/link3/")) {
let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewControlleripad : ViewWrapper = mainStoryboardIpad.instantiateViewController(withIdentifier: "Wrapper") as! ViewWrapper
initialViewControlleripad.memberActivation = components.description
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = initialViewControlleripad
self.window?.makeKeyAndVisible()
return true
} else {
if let webpageUrl = URL(string: components.description) {
application.open(webpageUrl)
}
return false
}
}
当我的iOS应用仍在后台时,一切运行良好。应用程序被杀死后,我尝试打开电子邮件中的链接,我将被重定向到初始ViewController,而不是先前代码中设置的那个。是什么导致此问题?我该如何解决?