2016-09-26 168 views
0

我已經使用Branch.io創建了我的應用程序的深層鏈接。但每次啓動應用程序時,它都會將我重定向到深層鏈接控制器。Branch.io Deeplink每次啓動應用程序時都會打開深層鏈接

我用下面的代碼中 - (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; 
} 

回答

0

你不應該從

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

打電話instantiateViewController...根據他們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); 
    } 
}]; 
+0

是的,我也實現了這個代碼,但它也返回了對於參數'clicked_branch_link'是,即使鏈接沒有被點擊。我認爲它可以在某些地方爲它的偏好節省價值。但是當我通過測試飛行測試它時,它工作正常。 –

+0

來自Branch.io的Alex在這裏:如果您正在進行廣泛的測試,可能會有多個鏈接點擊排隊等待該設備ID,並且SDK只需要按順序清除它們。如果您仍然有問題,請告訴我! –

+0

我有同樣的問題,我該如何清理? @AlexBauer – ovidiur

相關問題