NSUserDefault change notification handling in watchAppExtension

后端 未结 2 938
感情败类
感情败类 2020-12-31 14:17

I\'m creating a  Watch app just to display a value on the watch when the user taps on a table view in the iPhone/host app.

I would like to get a notification the va

相关标签:
2条回答
  • 2020-12-31 14:38

    I don't think iOS has capability of distributed notifications between app and extension, notifications will not work between both, instead you need to find a way in which both can monitor changes. For example files.

    As you already have created group, you can keep a file in the group folder and add a filewatcher in extension, update the file from app, and filewatcher will catch the change, and your work is done.

    For filewatcher see code here.

    Hope it helps.

    Cheers.

    Update

    Find File watcher Swift version here. Thanks @rivera for adding.

    0 讨论(0)
  • 2020-12-31 14:40

    You can try MMWormHole which provides :

    • a channel between the iOS device and the watch which enables you to send data back and forth between them.
    • Also provides a way to do Notifications without having to handle the file monitoring by urself.

    Using it ,That will be all the code needed to do notifications in ur app

    [self.wormhole passMessageObject:@{@"buttonNumber" : @(1)} identifier:@"button"];
    
    [self.wormhole listenForMessageWithIdentifier:@"button" 
      listener:^(id messageObject) {
        self.numberLabel.text = [messageObject[@"buttonNumber"] stringValue];
    }];
    
    0 讨论(0)
提交回复
热议问题