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

蹲街弑〆低调 提交于 2020-01-01 11:41:41

问题


I've set up universal links with the Branch SDK. The links are opening the app correctly, and application:continueUserActivity:restorationHandler: is called, but not `application:openURL:options:'

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    Branch.getInstance().application(app, open: url, options: options)
    return true
}

The deprecated application:openURL:sourceApplications:annotation is also not called. didFinishLaunchingWithOptions and willFinishLaunchingWithOptions both return true.

What could possibly causing openURL to not be called when the app opens from tapping a universal link?


回答1:


Clay from Branch here.

The application:openURL:sourceApplications:annotation function (now deprecate to application(_:open:options:)) is actually only called in response to the old Apple Linking system of standard URI schemes.

Universal links are actually handled within the application(_:continue:restorationHandler:) function.

// 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
}

Your deep link handling should mostly be dealt with in your handler callback:

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
}


来源:https://stackoverflow.com/questions/45381922/applicationopenurloptions-not-called-after-opening-universal-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!