0

错误在应用程序中实现了 branch.io。工作正常,除非应用程序未在后台运行并且单击了 branch.io 链接。它将打开应用程序并重定向到要显示共享内容但显示空屏幕或屏幕上没有内容的屏幕。如果应用程序在后台运行,它工作正常。为什么这是限制,或者我错过了一些东西。请指导,先谢谢了。

为了清楚起见,发布一些代码。

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

sleep(5);

ArticlesDetailViewController *controller = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"articlesDetail"];
 Branch *branch = [Branch getInstance];
[branch registerDeepLinkController:controller forKey:@"ScreenArticle"];
[branch initSessionWithLaunchOptions:launchOptions automaticallyDisplayDeepLinkController:YES];
}

//  Controller where redirected.

- (void)configureControlWithData:(NSDictionary *)data {
NSString *pictureUrl = data[@"ScreenArticle"];

iSBranch = 1;

strDate = data[@"CreatedDate"];
self.lblDate.text = [strDate uppercaseString];
self.lblTitle.text = data[@"Title"];
strDesc = data[@"Description"];
[self.txtDescription sizeToFit];
[self.txtDescription.textContainer setSize:self.txtDescription.frame.size];

NSString *strPreFont = @"<font face=\"Avenir Next\" color=\"#FFF\" size=\"5\">";

NSString *strPost = @"</font>";
NSString *htmlString = [NSString stringWithFormat:@"%@%@%@", strPreFont, strDesc, strPost];
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF16StringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
self.txtDescription.attributedText = attributedString;

strImgUrl = data[@"ImageName"];
[self.imgHeader sd_setImageWithURL:[NSURL URLWithString:strImgUrl] placeholderImage:[UIImage imageNamed:@"DummyImageFeaturedFirst"]];

// show the picture
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:pictureUrl]];
    UIImage *image = [UIImage imageWithData:imageData];
    dispatch_async(dispatch_get_main_queue(), ^{
        //self.productImageView.image = image;
        NSLog(@"got image");
    });
});
}

- (IBAction)closePressed {
[self.deepLinkingCompletionDelegate deepLinkingControllerCompleted];
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

mixpanel = [Mixpanel sharedInstance];

if(iSBranch)
{

}
else
{
    self.lblDate.text = [strDate uppercaseString];
    self.lblTitle.text = strTitle;
    //self.txtDescription.text = strDesc;

    [self.txtDescription sizeToFit];
    [self.txtDescription.textContainer setSize:self.txtDescription.frame.size];

    NSString *strPreFont = @"<font face=\"Avenir Next\" color=\"#FFF\" size=\"5\">";

    NSString *strPost = @"</font>";
    NSString *htmlString = [NSString stringWithFormat:@"%@%@%@", strPreFont, strDesc, strPost];
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF16StringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    self.txtDescription.attributedText = attributedString;

    [self.imgHeader sd_setImageWithURL:[NSURL URLWithString:strImgUrl] placeholderImage:[UIImage imageNamed:@"DummyImageFeaturedFirst"]];
}
}
4

2 回答 2

2

我在 didFinishLaunchingWithOptions 中使用initSessionWithLaunchOptions

像这样..我的快速语言代码

let branch: Branch = Branch.getInstance()
branch.initSessionWithLaunchOptions(launchOptions, andRegisterDeepLinkHandler: { params, error in
 do {
      if let _ = params {
          if params["video_id"] != nil{
            let videoId = params["video_id"] as! String
            print("brach data printing \(videoId)")
           //Get your data here and redirect also . 
           //I'm getting video_id from deeplinking. 
          }
      }
   }
})

如果您在此处无法快速理解该评论,我会将其转换为 Objective-C 。

我没有使用任何其他功能来重定向 . 我在本节中写下了该代码,它运行良好。

于 2016-05-09T10:39:45.373 回答
0

我相信问题可能是您在定义分支单例之前注册了深层链接视图控制器。尝试重新排列您的didFinishLaunchingWithOptions方法,如下所示:

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

  Branch *branch = [Branch getInstance];

  ArticlesDetailViewController *controller = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"articlesDetail"];
  [branch registerDeepLinkController:controller forKey:@"ScreenArticle"];
  [branch initSessionWithLaunchOptions:launchOptions automaticallyDisplayDeepLinkController:YES];
}

还有一个可用的TestBed 应用程序,您可能会发现它对参考有用。

于 2016-05-09T15:21:55.007 回答