在应用程序中实现了branch.io。工作正常,除非app未在后台运行且点击了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"]];
}
}
答案 0 :(得分: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中将其转换。
我没有使用任何其他功能进行重定向。我在本节中写下了这段代码并且工作得很好。
答案 1 :(得分: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 app可供参考。