Search code examples
apple-watchwatchos-2apple-watch-complication

Is there a way to update a complication directly from the iPhone app?


I'd like to allow the user to be able to bypass the watch app altogether if possible.

I've tried importing ClockKit on my ViewController to create an instance of CLKComplicationServer. I get the "No such module" error.

Is there a way to communicate directly with the complication from the iOS app?


Solution

  • CLKComplicationServer is part of ClockKit that is available only watchOS2.

    You can send data for complication from iOS using [WCSession transferCurrentComplicationUserInfo:]. Not like [WCSession transferUserInfo:] It will awake watchOS App, and deliver your message as soon as possible.

    It will awake your watchOS App, and call -(void)session:(WCSession *)session didReceiveUserInfo:(NSDictionary<NSString *,id> *)userInfo of Watch side WCSession's delegate. In this delegate, you can use ComplicationServer like this:

    CLKComplicationServer* server = [CLKComplicationServer sharedInstance];
    [server.activeComplications enumerateObjectsUsingBlock:^(CLKComplication * _Nonnull each, NSUInteger idx, BOOL * _Nonnull stop) {
        [server reloadTimelineForComplication: each];
    }];
    

    finally it will invoke your ComplicationController.