OGeek|极客世界-中国程序员成长平台

标题: ios - iPhone 到 WatchKit 的通信 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:15
标题: ios - iPhone 到 WatchKit 的通信

我可以使用

将数据从 Watch 发送到父应用
[WKInterfaceController openParentApplication:applicationData reply:^(NSDictionary *replyInfo, NSError *error) {}] 

api 但如何在 Objective C 中将数据从 iPhone 发送到 Watch。



Best Answer-推荐答案


您有一些方法可以实现这一目标。最简单的方法是使用 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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4