For watchOS 2
There is only one WCSession
method which would let you update your complication data while the watch app was not active.
Assuming your complication is active, and you have not exceeded the (iOS 10) number of transfers per day, transferCurrentComplicationUserInfo
will wake up your watch extension in the background, and immediately transfer the user info to your extension.
Your extension could then persist that data on the watch (for the watch app to use when it becomes active), before updating your complication.
func session(session: WCSession, didReceiveUserInfo userInfo: [String : AnyObject]) {
if let ... { // Retrieve exchange rate data from dictionary
// Add code here to update your cache/backing store with exchange rate
// ...
// Now update the complication
let complicationServer = CLKComplicationServer.sharedInstance()
guard let activeComplications = complicationServer.activeComplications else { // watchOS 2.2
return
}
for complication in activeComplications {
complicationServer.reloadTimelineForComplication(complication)
}
}
}
For watchOS 3
watchOS 3 supports background refresh app tasks. This means it is now possible for your watch app to update itself, its dock snapshot, and its complication in the background.
I've already covered this information in an existing answer, but will sum up the key takeaway here:
Apple recommends that you use each opportunity you are given regardless of whether your app is in the foreground or background to keep your complication, app, and dock snapshot up to date.
This is a radical change from merely updating the complication when the app isn't active, to now updating everything -- complication, app, and dock snapshot -- regardless of whether your watch app is in the foreground or the background.
A note on limits to updating frequently changing data
Regardless of which approach you use, keep in mind that you will be limited in the number of updates you can perform per day or per hour.
As Apple recommends, you should consider scheduling your exchange rate updates around the times when they would be needed. These two sessions cover when (as well as how) to update your watch app: