3

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.

Callum Jones
  • 595
  • 4
  • 15

1 Answers1

1

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)
}
ccjensen
  • 4,578
  • 2
  • 23
  • 25
  • 2
    How would you access the `didReceiveUserInfo` data easiest from the `ComplicationController`? My `didReceiveUserInfo` is in my `InterfaceController`. So does `didReceiveUserInfo` need to go in both `InterfaceController` and `ComplicationController`, or is there some easier/better way to access the data from `ComplicationController`? I assume there's gotta be, but thats what I'm trying to figure out too http://stackoverflow.com/questions/33190685/watchkit-complication-get-complication-data-from-extension-delegate – SRMR Oct 18 '15 at 14:32
  • 1
    did you get anywhere with this? i can't get my complication to update at all – mad_dog Nov 16 '15 at 11:32