I'm developing a single target watchOS app that obtains HealthKit information. I have the "Background Delivery" option checked under "Signing & Capabilities" for the watch target. The app does HKObserverQueries in the foreground that work as I would expect. But when I click the Digital Crown to return to clock face, the HKObserverQuery activity stops. I'm using Xcode 15.4, on Mac 14.5 and a Apple Watch Series 4 running 10.5.
HKObserverQuery not working in background
Yeah, there is currently a bug that prevents HKObserverQuery
from working in the background on watchOS. If you don't mind, please file a feedback report with your use case and post your report ID here. I'll make sure that your report is routed to the HealthKit team.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.
My colleague reminded me that the bug I mentioned was actually a feature request that had been addressed, and so I'd like to take a closer look at your issue to hopefully get to the bottom.
I'd like to start with gathering more information. Would you mind to share the following details:
- How did you implement the
HKObserverQuery
+enableBackgroundDelivery(for:frequency:withCompletion:)
? - How did you determine that the background delivery doesn't work?
Worth mentioning, the background update on watchOS is more restrictive than on iOS. Our documentation calls out the following:
“Also, in watchOS, the background updates share a budget with WKApplicationRefreshBackgroundTask tasks. Your app can receive four updates (or background app refresh tasks) an hour, as long as it has a complication on the active watch face.”
If you see that the background update happens, but not so frequently, it may be that your app runs out of the budget. In that case, the budget will automatically restore after a period of time.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.