我在我的项目中使用 Branch.io 从我的网站启动应用程序。我想要的是如果应用程序关闭,当我单击网络上的通用链接时,它将首先打开主页。相反,它打开了另一个。它适用于 iOS 8。但在 iOS 9+ 中,它总是打开 LaunchScreen。
请看一下我的代码:
应用委托:
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
}