application:openURL:options: 开启通用后不调用link

application:openURL:options: not called after opening universal link

我已经使用 Branch SDK 设置了通用 link。 link 正确打开应用程序,并且调用了 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 也不会被调用。 didFinishLaunchingWithOptionswillFinishLaunchingWithOptions 都 return 正确。

当应用程序通过点击通用 link 打开时,什么可能导致 openURL 不被调用?

此处 Branch 的粘土。

application:openURL:sourceApplications:annotation 函数(现已弃用 application(_:open:options:))实际上仅在响应标准 URI 方案的旧 Apple 链接系统时调用。

通用 link 实际上是在 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
}

您的深度 link 处理应该主要在您的处理程序回调中处理:

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
}