代码之家  ›  专栏  ›  技术社区  ›  Swati Gupta

树枝io Deeplink每次启动应用程序时都会打开deep链接

  •  0
  • Swati Gupta  · 技术社区  · 8 年前

    我用过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;
    }
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   Anton Malyshev    8 年前

    你不应该打电话 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);
        }
    }];