我使用Branch.io为我的项目从我的网站启动应用程序。我想要的是如果应用程序关闭,当我点击网络上的通用链接时,它将首先打开HomePage。相反,它打开了另一个。它适用于iOS 8.但在iOS 9+中,它始终打开LaunchScreen。
请看一下我的代码:
的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
}
答案 0 :(得分:0)
总结一下这个问题:
此案例中的问题与Universal Linking有关。以前,在iOS 8上使用URI Schemes,您可以使用$ deeplink_path在您的应用程序中进行路由。 Universal Links Branch现在建议使用存储在自定义字段中的链接数据来通知应用内路由决策,而不是使用$ deeplink_path,如下所述:https://dev.branch.io/getting-started/deep-link-routing/advanced/ios/#building-a-custom-deep-link-routing-method
此外,在Branch init完成块中找到用于应用内路由的代码非常重要,因为此完成块仅在收到来自Branch服务器的响应并且链接参数为可用。如果应用内路由的代码位于完成块之外(并且未被完成块调用),则很可能在分支实际返回链接参数之前做出路由决策。