ios - 应用程序 :openURL:options: not called after opening universal link

标签 ios swift ios-universal-links

我已经使用 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 也不会被调用。 didFinishLaunchingWithOptionswillFinishLaunchingWithOptions 都返回 true。

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

最佳答案

粘土来自 Branch在这里。

application:openURL:sourceApplications:annotation 函数(现在弃用为 application(_:open:options:))实际上只是为了响应旧 Apple 而被调用标准URI方案的链接系统。

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

关于ios - 应用程序 :openURL:options: not called after opening universal link,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45381922/

相关文章:

ios - 无法在 Swift 3 中以编程方式注册字体

swift - 在 Storyboard中添加自动布局,然后以编程方式更新它

ios - 使用 Codable 协议(protocol)仅解码 JSON 的一部分

swift - MPNowPlayingInfoCenter 停止更新进度条

iOS 9+ 通用链接不适用于 Google 应用

ios - 没有路径的域的通用链接

ios - 通用链接在真实设备上不起作用

objective-c - 长时间使用后应用程序和操作系统滞后

ios - 在 iPad 上 : UITableView's separator between header and cells

ios - 将焦点从一个 View Controller 转移到另一个 View Controller (以模态方式呈现),反之亦然