Search code examples
iosswiftwatchkit

Setting up initial data for a WatchOS complication


Let's say I have the following scenario:

User installs my WatchOS application on his watch. He never launches it, but he enables the complication. After the complication is enabled and visible, it should show real data.

I am struggling to find a place where to ask for that data.


Solution

  • Take a look at the getCurrentTimelineEntry(for:withHandler:) function in ClockKit. This is where watchOS queries for real data. So, the user doesn't have to launch the actual watchOS application since your complication can act independently by providing data to watchOS.

    After activating the watchOS complication, watchOS should automatically call the getCurrentTimelineEntry(for:withHandler:) function and will call it again after a given time interval specified in the getNextRequestedUpdateDate(handler:) function.