通用链接、continueUserActivity 和 sourceApplication 未被调用
Universal links, continueUserActivity and sourceApplication not being called
我终于设法实现了通用 links,如果我点击 link,它将打开我的应用程序。但它不会出现在继续用户 activity 或源应用程序中。因为我想将它重定向到特定的视图控制器。例如,如果我打开 "https://www.myWeb.com/forgotPassword"
,它将重定向到 forgotPasswordViewController
,我需要阅读 link.
为什么它不显示在继续用户 activity 中?
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
print(url)
let urlHost : String = url.host as String!
print("HELLO")
let main : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let inner : ResetPasswordViewController = main.instantiateViewController(withIdentifier: "ResetPasswordViewController") as! ResetPasswordViewController
self.window?.rootViewController = inner
self.window?.makeKeyAndVisible()
return true;
}
func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let url = userActivity.webpageURL!
print(url)
print("HELLO WORLD")
}
return true
}
这就是源应用程序发生的情况;谁能告诉我为什么会变成这样?
已解决
只是因为数据类型,我用 AnyObject 代替了 Any。
但是编译器没有告诉我是否不能使用 AnyObject
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
print("Continue User Activity: ")
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let url = userActivity.webpageURL!
print(url.absoluteString)
//handle url
}
return true
}
我终于设法实现了通用 links,如果我点击 link,它将打开我的应用程序。但它不会出现在继续用户 activity 或源应用程序中。因为我想将它重定向到特定的视图控制器。例如,如果我打开 "https://www.myWeb.com/forgotPassword"
,它将重定向到 forgotPasswordViewController
,我需要阅读 link.
为什么它不显示在继续用户 activity 中?
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
print(url)
let urlHost : String = url.host as String!
print("HELLO")
let main : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let inner : ResetPasswordViewController = main.instantiateViewController(withIdentifier: "ResetPasswordViewController") as! ResetPasswordViewController
self.window?.rootViewController = inner
self.window?.makeKeyAndVisible()
return true;
}
func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let url = userActivity.webpageURL!
print(url)
print("HELLO WORLD")
}
return true
}
这就是源应用程序发生的情况;谁能告诉我为什么会变成这样?
已解决 只是因为数据类型,我用 AnyObject 代替了 Any。 但是编译器没有告诉我是否不能使用 AnyObject
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
print("Continue User Activity: ")
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let url = userActivity.webpageURL!
print(url.absoluteString)
//handle url
}
return true
}