gpt4 book ai didi

ios - iOS 9+ 问题的 Branch.io 链接

转载 作者:可可西里 更新时间:2023-10-31 23:43:40 28 4
gpt4 key购买 nike

我在我的项目中使用 Branch.io 从我的网站启动应用程序。我想要的是,如果应用程序关闭,当我单击网络上的通用链接时,它将首先打开主页。相反,它打开另一个。它适用于 iOS 8。但在 iOS 9+ 中,它始终打开 LaunchScreen。

请看一下我的代码:

应用委托(delegate):

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.

let branch = Branch.getInstance()
branch.initSessionWithLaunchOptions(launchOptions) { (params, error) -> Void in
DHIndicator.hide()
if let _ = params {
print("kdlkasdlf: \(params.debugDescription)")
if let str = params["$deeplink_path"], url = NSURL(string: str as! String) {
NSLog("link: \(url)")
self.path = url.path
self.query = url.query
LaunchAppFlowManager.shareInstance.displayLaunchDetails()
} else {
// load your normal view
}
}
}
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.makeKeyAndVisible()
window?.backgroundColor = UIColor.whiteColor()
AccountFlowManager.shareInstance.start()
}

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
Branch.getInstance().handleDeepLink(url)
if AppDelegate.shareInstance().window?.rootViewController?.nibName != "LaunchScreenVC" {
DHIndicator.show()
}
return true
}

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
print(userActivity.webpageURL?.absoluteString)
if AppDelegate.shareInstance().window?.rootViewController?.nibName != "LaunchScreenVC" {
DHIndicator.show()
}
return Branch.getInstance().continueUserActivity(userActivity)
}

然后,启动应用程序的功能:

if let _ = AppDelegate.shareInstance().path, _ = AppDelegate.shareInstance().query {
let navi = UINavigationController(rootViewController: HomePageVC())
self.navi = navi
AppDelegate.shareInstance().window?.rootViewController = navi
} else {
let vc = LaunchScreenVC()
AppDelegate.shareInstance().window?.rootViewController = vc
}

最佳答案

总结一下这个问题:

  1. 在 iOS 8 上,当点击分支链接时,应用打开并显示正确的 ViewController
  2. 在 iOS 9 上,当分支链接是单击应用打开,但显示默认的 ViewController

本例中的问题与通用链接有关。以前,在 iOS 8 上使用 URI 方案,您将使用 $deeplink_path 在您的应用程序中进行路由。而不是使用 $deeplink_path,Universal Links Branch 现在建议使用存储在自定义字段中的链接数据来通知应用内路由决策,如下所述:https://dev.branch.io/getting-started/deep-link-routing/advanced/ios/#building-a-custom-deep-link-routing-method

此外,在 Branch init 完成 block 中找到用于应用内路由的代码也很重要,因为此完成 block 仅在收到来自 Branch 服务器的响应并且链接参数可用后才运行。如果应用内路由的代码位于完成 block 之外(并且未被完成 block 调用),则很可能会在 Branch 实际返回链接参数之前做出路由决定。

关于ios - iOS 9+ 问题的 Branch.io 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37558361/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com