分支Universal Link无法正常工作

时间:2016-12-05 19:11:08

标签: ios deep-linking branch.io ios-universal-links

我正在使用Branch.io在我的应用中实现通用链接。每次我复制并粘贴一个通用链接(从我的应用程序)到Notes我点击'打开(APP)',它会将我重定向到错误的视图控制器。它将我引导到用户首次打开应用程序时看到的主视图控制器。我的 AppDelegate.m 文件中的深层链接路由出现问题:

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

Branch *branch = [Branch getInstance];

WebDeepLinkViewController *WebDeepLinkViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
[branch registerDeepLinkController:WebDeepLinkViewController forKey:@"Article"];

1 个答案:

答案 0 :(得分:0)

来自Branch.io的Alex:

看起来你在呼叫instantiateInitialViewController。顾名思义,this loads the main view controller that the user sees when they first open the app。你想要instantiateViewControllerWithIdentifier

此外,您可能错过了一行,除非您只是没有将其包含在代码段中:

[branch initSessionWithLaunchOptions:launchOptions automaticallyDisplayDeepLinkController:YES];

更正的版本如下所示:

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

Branch *branch = [Branch getInstance];

WebDeepLinkViewController *WebDeepLinkViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"DeepLinkingController"];

[branch registerDeepLinkController:WebDeepLinkViewController forKey:@"Article"];
[branch initSessionWithLaunchOptions:launchOptions automaticallyDisplayDeepLinkController:YES];

DeepLinkingController是故事板ID。如果您不知道如何设置,可以找到说明here