【发布时间】:2015-07-24 13:20:40
【问题描述】:
我想在 watchOS 2 中将字典从 WatchKit 发送到 iPhone,并在不启动 iPhone 应用的情况下从 iPhone 获得回复(回调)。
在 watchOS 1 中,这可以通过在 Watch 中点击按钮时调用 openParentApplication 方法来实现:
@IBAction func btnTapped() {
let dictionary = ["Button":0]
WKInterfaceController.openParentApplication(dictionary, reply: { (replyInfo, error) -> Void in
print(replyInfo["ReturnButton"])
})
}
在 AppDelegate 类中:
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply {
int key = (int)[[userInfo objectForKey:@"Button"] integerValue];
NSMutableDictionary* dict = [[NSMutableDictionary alloc]init];
switch (key){
case 0:
[dict setObject:@"Button1" forKey:@"ReturnButton"];
break;
default:
break;
}
reply(dict);
}
它进入处理程序并在不启动 iOS 应用程序的情况下打印“Button1”。我不知道这对于 watchOS 2 是否可行。
【问题讨论】:
-
“openParentApplication”在后台打开父应用,实际上并没有启动它。
-
是的!我知道,“openParentApplication”正在后台打开父应用程序并在手表中发送回调而不启动 iPhone 应用程序,实际上这与我在手表 OS2 中想要的一样
标签: objective-c iphone swift watchkit apple-watch