Branch Universal Deep Link 不显示自定义视图控制器元素

Branch Universal Deep Link does not display custom view controller elements

所以我有一个 Universal link 通向我的应用程序中的视图控制器。在那个特定的视图控制器上,我显示了几个图像以及一个 web 视图。 webView 显示用户选择的 url。如何保存此自定义 url 以便在每次有人单击 link 时显示它?我认为此代码位于:

@synthesize deepLinkingCompletionDelegate;
 -(void)configureControlWithData:(NSDictionary *)data {


NSString *string = data[@"favoriteArticle"];

来自 Branch.io 的亚历克斯:

要做到这一点,您需要做两件事。

步骤 1

将要加载的文章 URL 存储为 Branch link 自定义参数之一。关于如何做到这一点的完整说明 here,但本质上:

BranchUniversalObject *branchUniversalObject = [[BranchUniversalObject alloc] initWithCanonicalIdentifier:@"item/12345"];
branchUniversalObject.title = @"My Content Title";
branchUniversalObject.contentDescription = @"My Content Description";
branchUniversalObject.imageUrl = @"https://example.com/mycontent-12345.png";
[branchUniversalObject addMetadataKey:@"favorite_article" value:@"https://example.com/path/to/article"]; // this is used to route inside the app
[branchUniversalObject addMetadataKey:@"property2" value:@"red"];

BranchLinkProperties *linkProperties = [[BranchLinkProperties alloc] init];
linkProperties.feature = @"sharing";
linkProperties.channel = @"facebook";
[linkProperties addControlParam:@"$desktop_url" withValue:@"https://example.com/path/to/article"]; // this is used for desktop visitors
[linkProperties addControlParam:@"$ios_url" withValue:@"https://example.com/path/to/article"]; // this is used for iOS mobile visitors without the app installed

第 2 步

然后,当应用程序在 link 单击后打开时,请注意该数据键。同样,full instructions,但基本上:

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

  // initialize the session, setup a deep link handler
  [[Branch getInstance] initSessionWithLaunchOptions:launchOptions
                          andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) {

    // start setting up the view controller hierarchy
    UINavigationController *navC = (UINavigationController *)self.window.rootViewController;
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *nextVC;

    // If the key 'favoriteArticle' is present in the deep link dictionary
    // then load the picture screen with the appropriate picture
    NSString * favoriteArticle = [params objectForKey:@"favorite_article"];
    if (favoriteArticle) {
      nextVC = [storyboard instantiateViewControllerWithIdentifier:@"ArticleVC"];
      [nextVC setArticleUrl: favoriteArticle];
    } else {
      nextVC = [storyboard instantiateViewControllerWithIdentifier:@"MainVC"];
    }

    // navigate!
    [navC setViewControllers:@[nextVC] animated:YES];
  }];

  return YES;
}

之后,在您的 ArticleVC 中检索 favoriteArticle 值并将其用于您的网络视图。

第 2 步(备选)

你提到的configureControlWithData方法在automatic deep link routing implementation中使用。您也许可以调整它以使用 webview,但我还没有亲自尝试过。它看起来像这样:

@synthesize deepLinkingCompletionDelegate;
- (void)configureControlWithData:(NSDictionary *)data {
    NSString *favoriteArticle = data[@"favorite_article"];

    // load the webview with the URL stored inside favoriteArticle
}