Handoff not working from native app to website

a 夏天 提交于 2019-12-21 05:15:22

问题


My devices:

  • iPad Mini (latest), iOS 8 dp5.
  • Macbook Air, Yosemite dp5.

I have Handoff working between the two above devices. Safari, Mail, Messages, Calendar, etc. all handoff with no problems.

I can even handoff between my website on the Air and my native app on the iPad.

What I can't do yet is go from my native app on the iPad to my website in Safari on my Air.

For the first view controller that loads in my native app, I have this:

- (void)viewDidLoad

{
    [super viewDidLoad];

    NSUserActivity *webHandoff = [[NSUserActivity alloc] initWithActivityType:@"com.myApp.iphone.staging.webbrowsing"];

    webHandoff.webpageURL = [NSURL URLWithString:@"http://staging.myApp.com"];

    [webHandoff becomeCurrent];
}

In my app's Info.plist file, I have this:

<key>NSUserActivityTypes</key>
<array>
      <string>com.myApp.iphone.staging.webbrowsing</string>
</array>

Am I missing something or do I have something configured incorrectly?

Thanks for any help!


回答1:


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.



来源:https://stackoverflow.com/questions/25128878/handoff-not-working-from-native-app-to-website

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