We are to trying to fetch data from Health kit on Specific Interval of time. One first attempt we are able to fetch data from HealthKit and It shows last collected samples.
After first attempt, We measured Heart rate from Watch, So It should be synchronised with HealthKit .
But now we are making second attempt from mobile to read latest added sample from Health kit, But it is returning what we had on first attempt, not the last one which we measured from Watch.
Once we put our Mobile app in background for even a second and open it again, Then health kit provides the latest reading (taken from watch).
It seems Health kit is not being Synchronised while our app (3rd party app) is running in Foreground.
In short we want to track Live Heart rate (also other data) whole Day (24 * 7) taken by watch and send to Mobile App so it can sync with our server.
Can please anyone help with this ? Any kind of solution to get over this stuff. Thank you in advance.
We already tried
Get live heart rate from Watch by HKWorkoutSession and send it to Mobile App via WCConnection. But WCSession becomes unreachable when Watch screen becomes dark. so we are unable to send data to watch.
We tried HKObserverQuery, But when app goes into background it stops running after 30 seconds of entering in background or after giving 3 or 4 results.
We tried HKSampleQuery in Timer to fire after every 5 seconds. And we got this use case as described problem.