Branch.io Deeplink每次启动应用程序时都会打开深层链接
问题描述:
我已经使用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;
}
答
你不应该从
- (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);
}
}];
是的,我也实现了这个代码,但它也返回了对于参数'clicked_branch_link'是,即使链接没有被点击。我认为它可以在某些地方为它的偏好节省价值。但是当我通过测试飞行测试它时,它工作正常。 –
来自Branch.io的Alex在这里:如果您正在进行广泛的测试,可能会有多个链接点击排队等待该设备ID,并且SDK只需要按顺序清除它们。如果您仍然有问题,请告诉我! –
我有同样的问题,我该如何清理? @AlexBauer – ovidiur