每次启动应用程序时,Branch.io Deeplink 都会打开深层链接
Posted
技术标签:
【中文标题】每次启动应用程序时,Branch.io Deeplink 都会打开深层链接【英文标题】:Branch.io Deeplink is opening the deep link every time the app is launched 【发布时间】:2016-09-26 05:58:38 【问题描述】:我使用 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】:你不应该打电话给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);
];
【讨论】:
是的,我也实现了此代码,但即使未单击链接,参数“clicked_branch_link”也返回“是”。我认为它可以根据自己的喜好在某处保存价值。但是当我通过试飞对其进行测试时,它工作正常。 来自 Branch.io 的 Alex 在这里:如果您进行广泛测试,您可能有多个链接点击排队等待该设备 ID,而 SDK 只需要按顺序清除它们。如果您仍有问题,请告诉我! 我有同样的问题,我该如何清理? @AlexBauer以上是关于每次启动应用程序时,Branch.io Deeplink 都会打开深层链接的主要内容,如果未能解决你的问题,请参考以下文章
在branch.io中的redeemRewards函数调用时每次显示错误消息
branch.io:无法从 javascript 检测已安装的应用程序
Branch.io SDK 无法在 Unity3D 中的 Android 构建上初始化