Branch.io Deeplink每次启动应用程序时都会打开深层链接

时间:2016-09-26 05:58:39

标签: ios objective-c branch.io

我使用Branch.io为我的应用创建了深层链接。但每次启动应用程序时,它都会将我重定向到深层链接控制器。

我在 - (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
        processOpenURLAction:url
           sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                  annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
                  iosVersion:9];

    return YES;
}



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

     [self application:application
        processOpenURLAction:url
           sourceApplication:sourceApplication
                  annotation:annotation
                  iosVersion:8];

    return YES;
}

1 个答案:

答案 0 :(得分:0)

您不应该从

致电instantiateViewController...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

根据他们的docs,您应该使用以下代码:

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);
    }
}];