iOS 从 iphone 切换到 macbook safari/chrome

标签 ios objective-c ios8 handoff

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

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

它似乎没有出现在我的 dock 上 - 如果您想使用 safari,是否需要特殊的 Activity Type

最佳答案

好的,经过测试,您似乎需要将 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

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

关于iOS 从 iphone 切换到 macbook safari/chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30592960/

相关文章:

ios - 设置状态栏文本的自定义颜色

iOS 在 App Store 更新中减少了二进制文件的大小

ios - 在 Objective - C 中创建具有适当格式和图像的 PDF

iOS:如何使用 NSTimer 逐步画圆

ios - 计算器的方案是什么?

ios - 如何修复 swift 4 中的 UITableView 单元格重复

ios - 缩小 uilabel 背景以适应分配的空间

swift - 使用 swift 添加多个 View 到选项卡 Controller 内的 View Controller

ios - 退出我的应用程序后未显示蓝色横幅 "Your app is using your location"

xamarin.ios - iOS8:backgroundSessionConfiguration 已弃用