4

我想从我的应用程序发送一个 URL,以便使用切换在笔记本电脑网络浏览器上打开。我已将活动类型添加到我的应用程序的NSUserActivityTypes. 到目前为止,这是我的代码:

- (void)startHandoff {
    NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"com.me.browse"];
    activity.webpageURL = [NSURL URLWithString:_wakeUrl];
    [activity becomeCurrent];
}

它似乎没有出现在我的码头上 -Activity Type如果你想使用 safari,它是否需要特别的?

4

1 回答 1

3

好的,经过测试,您似乎需要将 声明NSUserActivity为实例变量:

所以这不起作用:

@interface TestViewController () {
}

@end

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //init hand off
    NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"com.app.browse"];
    activity.webpageURL = [NSURL URLWithString:@"http://www.stackoverflow.com"];
    [activity becomeCurrent];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

但这很好用:

@interface TestViewController () {
      NSUserActivity *activity;
}

@end

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //init hand off
   activity = [[NSUserActivity alloc] initWithActivityType:@"com.app.browse"];
    activity.webpageURL = [NSURL URLWithString:@"http://www.stackoverflow.com"];
    [activity becomeCurrent];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

不知道为什么,我现在正在研究

于 2015-06-02T10:44:18.487 回答