Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update iOS app with Apple Watch heart rate via healthkit? (HealthKit sync)

My watch app is easily capable of reading new heart rate data from HealthKit's new updateHandler in HKAnchoredObjectQuery.

Trouble is, the health store that the phone app observes seems to be unsynchronized with the watch.

Suspending the app and resuming it will sometimes prompt HealthKit to do (what seems to be) a synchronization between the watch's health store and the phone's store. I don't know why that is.

What I need is some way to continuously re-sync the health store between devices. If I simply send the newest heart rate data from the watch to the phone app with WatchConnectivity, then I can indeed get the data I need for display, but then if I submit such data to the store, I'll get duplicates when the watch's store DOES sync.

This is a major problem because it ruins HealthKit as a reliable single location to read and write health data.

Edit: Apple Bug Report radar https://openradar.appspot.com/radar?id=5033927626457088

like image 961
TealShift Avatar asked Oct 19 '22 02:10

TealShift


1 Answers

There is no way for your app to force the HealthKit synchronize data between the watch and the phone. What you are already doing with WatchConnectivity is the recommended approach to displaying live data from the watch.

like image 185
Allan Avatar answered Nov 15 '22 03:11

Allan