Handoff not working from native app to website

妖精的绣舞 提交于 2019-12-03 15:46:37

I made two significant changes to my code:

1) configure/destroy and set the NSUserActivity object in viewDidAppear/disappear as opposed to viewDidLoad:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    NSUserActivity *webHandoff = [[NSUserActivity alloc] initWithActivityType:@"com.myApp.iphone.staging.web-browsing"];
    webHandoff.webpageURL = self.handoffWebpageURL;
    [self setUserActivity:webHandoff];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];

    [self.userActivity invalidate];
}

2) Since UIViewController is a subclass of UIResponder and UIResponders have a userActivity property, instead of calling [webHandoff becomeCurrent] I simply called [self setUserActivity:webHandoff];

Not sure why moving it out of viewDidLoad had any impact, and not sure why I need to set it to the viewController's instance of NSUserActivity, but the changes above give me a solid and reliable handoff experience throughout my entire app.

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