ios - 使用 NSUserActivity 的 Handoff 中的 userInfo 是空的

标签 ios iphone watchkit handoff

我正在尝试从我的 WatchKit 应用程序发送一个字符串: 我可以通过锁定屏幕正常启动应用程序,但是当调用 continueUserActivity 方法时,userActivity.userInfo 不包含任何值,我在这里遗漏了什么吗?

-我得到的唯一值是 activityType

观看:

- (void)createActivity {
    self.activity = [[NSUserActivity alloc] initWithActivityType:@"com.myApp.urlSend"];
    [self.activity setUserInfo:@{@"url":self.wake.href}];
    [self.activity setTitle:self.wake.title];
    [self.activity becomeCurrent];
}

电话:

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler {

    NSString *url = userActivity.userInfo[@"url"];
}

最佳答案

我刚刚注意到您正在自己创建事件。如果您查看文档,您会发现与其他平台相比,Handoff 在 Watch 上的工作方式略有不同:https://developer.apple.com/library/prerelease/ios/documentation/WatchKit/Reference/WKInterfaceController_class/index.html#//apple_ref/occ/instm/WKInterfaceController/updateUserActivity:userInfo:webpageURL :

您只需调用 updateUserActivity 并在该调用中添加您的 userInfo 字典。

关于ios - 使用 NSUserActivity 的 Handoff 中的 userInfo 是空的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30054937/

相关文章:

ios - UIAlertView元数据

ios - Firebase : login error

iphone - 将图像保存到 iPhone 时出错

ios - 为什么在 didFailWithError 之后我收到错误的 GPS 位置?

objective-c - watch 套件 : is it possible to vibrate watch programmatically?

ios - 如何使用 Assets 库获取 UIImagePickerController 中的文件名?

ios - 在 Swift 中使用闭包作为唯一参数初始化对象

iphone - 使 UIView 变暗

ios - 动态更改 CustomTableViewCell 上的图像

avfoundation - Apple Watch 可以使用 AVFoundation 吗?