适用于iOS 9及以上版本的Branch.io链接
问题描述:
我使用Branch.io为我的项目从我的网站启动应用程序。我想要的是,如果应用程序关闭,当我点击网络上的通用链接时,首先会打开主页。相反,它打开了另一个。它适用于iOS 8,但在iOS 9+中,它始终打开LaunchScreen。适用于iOS 9及以上版本的Branch.io链接
请看看我的代码:
的AppDelegate:
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)
}
而且,FUNC键启动应用程序:
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
}
答
总结问题:
- 在iOS 8上,单击分支链接时,应用程序o笔和节目 正确的ViewController
- 在iOS 9,当分叉路段是 点击应用程序打开,但默认视图控制器显示
在这种情况下,问题与通用链接。以前,在iOS 8上使用URI Schemes,您可以使用$ deeplink_path在应用内进行路由。通用链接分支现在推荐使用存储在自定义字段中的链接数据来通知应用内路由决策,而不是使用$ deeplink_path,因此如下所述:https://dev.branch.io/getting-started/deep-link-routing/advanced/ios/#building-a-custom-deep-link-routing-method
此外,找到用于应用内的代码非常重要因为该完成块仅在收到来自分支机构的服务器的响应并且链接参数可用之后才运行。如果应用内路由的代码位于完成块之外(并且未由完成块调用),则可能会在Branch实际返回链接参数之前进行路由决策。
亚历克斯与Branch.io在这里:它听起来像通用链接可能没有完全配置在您的应用程序。我们能否看到您用于测试的示例链接?如果您不想公开分享这些信息,请随时[提交支持请求](https://support.branch.io)! –
这里有两个测试链接:https://8obj.app.link/stream?$deeplink_path=onedoor /onedoor/stream?id = 1/undefined和https://8obj.app.link/stream?$ deeplink_path = onedoor:// onedoor /流ID = 1/617c30ed70384800d838417b68d1e7ab。我也已经提交了一张票。所以请检查。 –
我们会看看并回复你。感谢您的链接! –