Communicating Updates between iPhone and Watch with SharedData

守給你的承諾、 提交于 2019-12-02 07:17:57

A very common solution and one of the only ways is to use MMWormhole.

MMWormhole uses the CFNotificationCenter to communicate changes instantaneously across the app and the extension, passing information through shared application groups.

Example of passing data through from the MMWormhole GitHub README:

// Sender (Watch Extension)
[self.wormhole passMessageObject:@{@"buttonNumber" : @(1)} identifier:@"button"];

// Receiver (Phone)
[self.wormhole listenForMessageWithIdentifier:@"button" 
  listener:^(id messageObject) {
    self.numberLabel.text = [messageObject[@"buttonNumber"] stringValue];
}];
vomako

There are different ways.

  1. You can use MMWormhole
  2. If you do not like to use a third-party library, you may use Darwin notifications directly. A good tutorial is already available on stackoverflow.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!