在应用程序中实现了 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"]];
}
}