branch.io redirects to empty content in app, if app is not running in background

巧了我就是萌 提交于 2019-12-12 03:45:53

问题


Implemented the branch.io in the application. Working fine except if app is not running in background and branch.io link clicked. It will open the app and redirect to the screen where shared content to be shown but showing the empty screen or no content on screen.If app is running in background it works fine. Why so is it the limitation or i am missing something. Please guide, thanks in advance.

Posting some code for clarity.

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

回答1:


I'm using initSessionWithLaunchOptions in didFinishLaunchingWithOptions

like this .. my code in swift language

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. 
          }
      }
   }
})

If you have problem in swift for understanding that comment here I'll convert it in Objective-C .

I'm not using any other function for redirecting . I wrote down that code in this section and its work well .




回答2:


I believe the issue may be that you're registering your deep linked view controller before defining the Branch singleton. Try rearranging your didFinishLaunchingWithOptions method as follows:

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

There is also a working TestBed app you might find useful for reference.



来源:https://stackoverflow.com/questions/37112732/branch-io-redirects-to-empty-content-in-app-if-app-is-not-running-in-background

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!