swiftwatchkitwatchosclockkit

Having complication data up to date when the user unlocks their watch?


I'm currently working on a simple app that displays data received over the network in a watchOS complication. Notably, this data is only relevant for ~30 minutes before a new network fetch is required.

I'd like to have the complication be up to date when the user unlocks their watch in the morning (this is a common use case presented by Apple).

Is it possible to receive some kind of background task when the user unlocks their watch? If I schedule a background task and the watch is locked and charging when the refresh happens, will the background task still fire? What techniques can I use to have data ready for the user when they wake up and unlock their watch? Is there documentation specifically focusing on background tasks when the watch is locked?


Solution

  • As far as I know, the watch works in its locked state only slightly differently from its unlock state.
    One difference is the display of complications:
    You can specify the privacy behaviour, i.e. what the clock face displays as complication (you can select what is displayed on the lock screen).
    So, to my mind, it is possible to run background tasks as scheduled when the watch is locked and charging. Thus the data will automatically be ready when the watch is unlocked.
    For this reason, there is no special documentation what happens when the watch is locked, except for some special cases, as what is displayed on the watch face in the locked state.