We are using Branch to implement deep linking in our iOS app. Now if I run the application, and then try to open it through the link by branch, the branch.initSession gets called and I can access the deep link data. However, if I try to open the branch link directly when the app is not launched, the andRegisterDeepLinkHandler callback from branch.initSession does not get executed - this basically nullifies the point of deep linking.
Our AppDelegate code:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let branch: Branch = Branch.getInstance()
branch.initSession(launchOptions: launchOptions, andRegisterDeepLinkHandler: {params, error in
DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
let alert = UIAlertController(title: "Branch", message: "\(params as? [String: AnyObject])", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.window?.rootViewController?.present(alert, animated: false, completion: nil)
})
if error == nil {
// params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
// params will be empty if no data found
// TODO: ... insert custom logic here ...
print("params: %@", params as? [String: AnyObject] ?? {})
}
})
...
// facebook SDK login integration
return SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
// pass the url to the handle deep link call
let branchHandled = Branch.getInstance().application(application,
open: url,
sourceApplication: sourceApplication,
annotation: annotation)
return branchHandled
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
// pass the url to the handle deep link call
let branchHandled = Branch.getInstance().application(app,
open: url,
options: options)
return branchHandled
}
