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

时间:2016-12-11 06:58:04

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

所以我有一个通用链接,可以在我的应用中找到一个视图控制器。在该特定视图控制器上,我显示了几个图像以及Web视图。 webView显示用户选择的URL。如何保存此自定义网址,以便每次有人点击该链接时都会显示该自定义网址?我认为这个代码在:

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


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

1 个答案:

答案 0 :(得分:0)

来自Branch.io的Alex:

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

第1步

将要加载的文章的URL存储为分支链接自定义参数之一。有关如何执行此操作的完整说明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步

然后,当点击链接后应用程序打开时,请注意该数据密钥。同样,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
}