Handoff not working from native app to website

后端 未结 1 1003
小鲜肉
小鲜肉 2021-02-10 02:47

My devices:

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

I have Handoff working between the two above devices. Safari, Mail, M

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-10 03:20

    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.

    0 讨论(0)
提交回复
热议问题