2016-12-05 73 views
0

我正在使用Branch.io在我的應用程序中實現Universal Links。每次我複製並粘貼Universal Link(從我的應用程序)到Notes時,點擊'OPEN IN(APP)',它會將我重定向到錯誤的視圖控制器。它引導我到用戶第一次打開應用程序時看到的主視圖控制器。一定出事了與我的深層鏈接路由在我AppDelegate.m文件:Branch Universal Link不工作

- (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"]; 

回答

0

亞歷克斯從Branch.io這裏:

它看起來像您所呼叫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

+0

好的,在我更正了代碼後,我測試了它並將通用鏈接發送給了我的應用程序,接受了整個屏幕變爲白色。當我添加'[branch initSessionWithLaunchOptions:launchOptions automaticallyDisplayDeepLinkController:YES]';'應用程序的視圖控制器變成完全白色。什麼可能是錯的? – Elizabeth429

+0

很難分辨...你能分享你的完整AppDelegate和視圖控制器代碼嗎?如果您不想在此處發佈此信息,請隨時爲分支集成團隊 –

+0

[提交門票](https://support.branch.io/support/tickets/new)發現問題。通用鏈接使用正確的代碼將我帶到了正確的視圖控制器。但是,視圖控制器元素缺失,其中包含按鈕和自定義Web視圖。唯一正確的元素是圖像和標籤。我如何保留這些元素? – Elizabeth429