Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

transferCurrentComplicationUserInfo and ComplicationController

I'm looking to send data to my complication as part of a didReceiveRemoteNotification to update the data displayed but there seems to be little documentation from Apple on how to setup the relationship between this and the complication itself.

When a ComplicationController is created, am I supposed to create a WCSession as well and begin listening for the delegate calls? I'm managed to place it into getPlaceholderTemplateForComplication and this seems to work when the iOS application is running but not when the app has been killed (or no longer running).

I'm curious if anyone has a good guide for getting data to the watch as part of a remote JSON push notification when the iOS app is running or not.

like image 863
Callum Jones Avatar asked Apr 22 '26 01:04

Callum Jones


1 Answers

I'd recommend watching the WatchConnectivity session from WWDC as it covers updating complications quite a bit towards the end.

In summary, in the iOS app once you have the contents to send:

    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);
}

and on the watch side:

@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)
}
like image 142
ccjensen Avatar answered Apr 23 '26 14:04

ccjensen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!