我建议观看来自 WWDC 的 WatchConnectivity 会话,因为它涵盖了接近尾声的更新复杂性。
总之,在 iOS 应用程序中,一旦您有要发送的内容:
NSDictionary *userInfo = // data to send
[[WCSession defaultSession] transferComplicationUserInfo:userInfo];
...
- (void)session:(WCSession * __nonnull)session didFinishUserInfoTransfer:(WCSessionUserInfoTransfer *)userInfoTransfer error:(nullable NSError *)error {
// handle error
NSLog(@"%s %@ (%@)", __PRETTY_FUNCTION__, userInfoTransfer, error);
}
在手表方面:
@property WCSession *session;
...
_session = [WCSession defaultSession];
_session.delegate = self;
[_session activateSession];
...
- (void)session:(WCSession *)session didReceiveUserInfo:(NSDictionary<NSString *, id> *)userInfo {
// persist data and trigger reload/extend of complication(s)
}