我可以使用
将数据从 watch 发送到家长应用程序[WKInterfaceController openParentApplication:applicationData reply:^(NSDictionary *replyInfo, NSError *error) {}]
api 但如何在 Objective C 中将数据从 iPhone 发送到 Watch。
最佳答案
您有一些方法可以实现这一目标。最简单的一种是使用 MMWormhole .
您使用以下方式发送数据:
[self.wormhole passMessageObject:@{@"titleString" : title}
identifier:@"messageIdentifier"];
您可以使用以下方式收到它:
[self.wormhole listenForMessageWithIdentifier:@"messageIdentifier"
listener:^(id messageObject) {
// Do Something
}];
请注意,虫洞使用应用程序组进行通信,因此您需要启用它。
MMWormhole 在底层使用的是 CFNotificationCenterGetDarwinNotifyCenter
。实现很简单,如果您想自己实现,您可以了解有关 CFNotificationCenterGetDarwinNotifyCenter
in this medium post 的更多信息。 .
关于ios - iPhone 到 WatchKit 的通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30120666/