0

errorImplemented 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"]];
}
}
iPhone 7
  • 1,731
  • 1
  • 27
  • 63

2 Answers2

2

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 .

Jogendra.Com
  • 6,394
  • 2
  • 28
  • 35
  • Would also like to mention, that i debugged the same case just now, branch.io bringing data with it and also assigning values to label and all, but still not reflecting on screen. – iPhone 7 May 09 '16 at 10:56
  • I used same code before 4-5 days and now my app live and its working fine with sharing – Jogendra.Com May 09 '16 at 11:38
  • Hello, i want to ask one thing, can you guide please. Currently i am redirecting the app to one screen only, but i have to share multiple contents so need to redirect to multiple screens. Ho to handle this please guide. Hope i made my question clear. – iPhone 7 May 11 '16 at 07:01
  • Please pass screen name while sharing and get again while retrieving data and check here – Jogendra.Com May 11 '16 at 07:47
  • Please check in my question as passed ArticlesDetailScreen there similarly add code for another screen or need to implement some checks. – iPhone 7 May 11 '16 at 07:59
  • my means pass a string with screen name and on getting data check that screen name using if condition . – Jogendra.Com May 11 '16 at 08:54
  • Can you please guide me i am stuck, i am implementing same thing in swift 2.3 and now i am facing issue. Attached screen shot please check will also add code in question, please check. – iPhone 7 Dec 16 '16 at 06:16
0

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.

Alex Bauer
  • 13,147
  • 1
  • 27
  • 44
  • No Alex that's not the issue, it doesn't reflect any change. – iPhone 7 May 10 '16 at 05:53
  • Are you using the Facebook SDK or any other libraries that could be interrupting the app launch queue? – Alex Bauer May 10 '16 at 06:12
  • Actually i am using UITextView to display the html content. So, the issue is when app redirected to the content, if html contains images to display in UITextView it doesn't scroll. But if i go to same screen within the app from normal flow it works fine. So, i am not getting the reason for this as the code is same, working in one case not in another case. Hope i made my point clear. – iPhone 7 May 10 '16 at 06:26
  • So just to clarify: this is working correctly *if you open the app normally, without using a Branch link* and it's also working correctly *if the app is already running in the background and then you open a Branch link*, but it is NOT working if you open a Branch link when the app is not running in the background? – Alex Bauer May 10 '16 at 18:50
  • "branch.io redirects to empty content in app, if app is not running in background" This problem is solved, there was initialisation issue. But problem is coming as described above, scrollview->UITextview->contains images and content doesn't scroll when open from branch.io link except first time. – iPhone 7 May 11 '16 at 05:43