我已经与Branch SDK建立了通用链接。链接正确打开应用程序,并调用application:continueUserActivity:restorationHandler:
,但不是`application:openURL:options:'
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
Branch.getInstance().application(app, open: url, options: options)
return true
}
也不会调用已弃用的application:openURL:sourceApplications:annotation
。 didFinishLaunchingWithOptions
和willFinishLaunchingWithOptions
都返回true。
当应用程序通过点击通用链接打开时,什么可能导致openURL无法被调用?
答案 0 :(得分:5)
来自Branch的粘土。
application:openURL:sourceApplications:annotation
函数(现在弃用到application(_:open:options:)
)实际上只是为响应标准URI方案的旧Apple Linking系统而调用。
通用链接实际上是在application(_:continue:restorationHandler:)
函数内处理的。
// Respond to URI scheme links
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
// pass the url to the handle deep link call
Branch.getInstance().application(app, open: url, options: options)
// do other deep link routing for the Facebook SDK, Pinterest SDK, etc
return true
}
// Respond to Universal Links
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
// pass the url to the handle deep link call
Branch.getInstance().continue(userActivity)
return true
}
您的深层链接处理应主要在您的处理程序回调中处理:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let branch: Branch = Branch.getInstance()
branch?.initSession(launchOptions: launchOptions, deepLinkHandler: { params, error in
if error == nil {
// params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
print("params: %@", params.description)
}
})
return true
}