Branch.io Deeplink 每次启动应用程序时都会打开 deep link
Branch.io Deeplink is opening the deep link every time the app is launched
我已经使用 Branch.io 为我的应用创建深度 link。但每次启动应用程序时,它都会将我重定向到深度 link 控制器。
我在 - (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;
}
你不应该从
打电话给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);
}
}];
我已经使用 Branch.io 为我的应用创建深度 link。但每次启动应用程序时,它都会将我重定向到深度 link 控制器。
我在 - (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;
}
你不应该从
打电话给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);
}
}];