swiftyboi
swiftyboi

Reputation: 3221

Is there a way to run code once a day in the background on Apple Watch?

I want to add a Complication to my Watch app that shows information retrieved from the internet. This information changes every day.

I need to find a way to retrieve this information without having to open the Watch app or iOS app daily.

I know running code in the background isn't really allowed on iOS, but it seems like a basic necessity for running Complications on the Watch, so maybe it's allowed on WatchOS?

Does anybody know how to do this?

Upvotes: 2

Views: 335

Answers (2)

Cobra
Cobra

Reputation: 369

Have a look at getNextRequestedUpdateDateWithHandler: in the ComplicationController. It allows you to request the next time you would like the complication code to be woken up. It will wake up in requestedUpdateDidBegin at the approximate time you request (within some limits, 24 hours should be fine.)

Upvotes: 1

Lorenzo
Lorenzo

Reputation: 3387

The first time the watch is active you could request the data from your server, update your internal data and save internally that the information of the current day is read. In this way you can avoid the background activity. You should check only the time (and date) when you activate your WatchApp.

Upvotes: 0

Related Questions