Reputation: 3920
Is it somehow possible to get live stats from the Apple-Watch about the users heart rate? Currently I only get callbacks on the watch as long as the app is open and the screen is active. Then I can send them to the Phone using the WCSession
.
But having live stats on the phone without the watch being turned on is not possible, right?
I would have to query the HealthStore after the workout is completed? And how long would I have to wait on the phone after finishing my workout on the Watch for the Heart-Rate data to be synced? What would be the best practice to add heart-rate data to my GPS trackpoints that I record? Just query the HealthStore some time after the activity and try to match the points by timestamp?
Any advice or tipps are very welcome :)
Upvotes: 1
Views: 2260
Reputation: 7343
Apps on watchOS may only run when the screen of the watch is on so practically speaking there is no way to reliably stream data, like the user's heart rate, from the watch to an app on the phone.
When the app on the watch does get an opportunity to run, it can collect heart rate samples from HealthKit and send them to the companion at that point.
Displaying live heart rate statistics on the phone is not possible because your app cannot control how frequently data is synced from the watch to the phone.
Upvotes: 0
Reputation: 20237
If you start a HKWorkoutSession on your Apple watch results are written to HealthKit in 5 second intervals (even if the watch screen is off). This data is automatically synced by Apple with your iPhone in the same 5 second intervals. If you create a health kit streaming query on your iPhone, you should be able to get "near live" stats. Take a look at this answer for more details on how to create a streaming health kit query.
Upvotes: 2