【发布时间】:2016-09-30 05:07:29
【问题描述】:
我在项目中使用 Branch.io 从我的网站启动应用程序。我想要的是如果应用程序关闭,当我单击网络上的通用链接时,它将首先打开主页。相反,它打开了另一个。它适用于 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)
}
并且,启动应用程序的功能:
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
}
【问题讨论】:
-
Alex 和 Branch.io 在这里:听起来通用链接可能没有在您的应用程序中完全配置。我们可以看到您用于测试的示例链接吗?如果您不想公开分享该信息,请随时submit a support ticket!
-
这里有两个测试链接:8obj.app.link/stream?$deeplink_path=onedoor://onedoor/…和8obj.app.link/stream?$deeplink_path=onedoor://onedoor/…。我也已经提交了一张票。所以请检查。
-
我们会查看并回复您。感谢您的链接!
-
@AlexBauer 请再次查看我的电子邮件。
-
我想我遇到了同样的问题。 @AlexBauer 你能帮忙吗?
标签: ios swift deep-linking branch.io ios-universal-links