Swati Gupta Swati Gupta - 1 year ago 134
Objective-C Question

Branch.io Deeplink is opening the deep link every time the app is launched

I have used Branch.io for creating deeplink for my app. But it's redirecting me to the deep link controller every time app is launched.

I have used following code in -

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Branch *branch = [Branch getInstance];

HomeDetailsViewController *controller = (HomeDetailsViewController*)[[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"HomeDetailsViewControllerID"];

[branch registerDeepLinkController:controller forKey:@"bucketId"];
[branch initSessionWithLaunchOptions:launchOptions automaticallyDisplayDeepLinkController:YES];


// Respond to Universal Links - Branch io
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler {
BOOL handledByBranch = [[Branch getInstance] continueUserActivity:userActivity];

return handledByBranch;

-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options NS_AVAILABLE_IOS(9_0) {

[[Branch getInstance] handleDeepLink:url];

[self application:app

return YES;

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
[[Branch getInstance] handleDeepLink:url];

[self application:application

return YES;

Answer Source

You should not call instantiateViewController... from

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

According to their docs, you should use the following code instead:

Branch *branch = [Branch getInstance];
[branch initSessionWithLaunchOptions:launchOptions andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) {
    if (!error && params) {
        // 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
        // ... insert custom logic here ...
        NSLog(@"params: %@", params.description);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download