How to get Apple Watch to send workout session data to my fitness app instantly

I am working with Apple HealthKit, and I need to add functionality to my app that allows a user's Apple Watch to automatically send the relevant data for their workout session (e.g. vo2 max, start timestamp, end timestamp, heartbeat, duration etc) as soon as they end their workout. This would need to work for any type of workout they do.

E.g. if they are doing a running session, when they end their workout my app needs to receive the data for that running session almost instantly.

I know that enableBackgroundDelivery allows my app to listen to changes in Apple Health in the background, but I'm not sure which method in HealthKit will allow me to implement the above use case.

Does anyone have any pointers? I just want to know what methods in HealthKit will allow me to achieve this.

Accepted Reply

It would be good to understand more of the use case/need for the immediate syncing... By default data from watch will sync to phone (if it's within range) when the workout completes so you could listen on the phone as well. Yes, enableBackgroundDelivery is the right API to be used. And it needs to be used in conjunction with HKObserverQuery. See the following

https://developer.apple.com/documentation/healthkit/hkobserverquerycompletionhandler

https://developer.apple.com/documentation/healthkit/hkobserverquery/executing_observer_queries

  • @Frameworks Engineer , thanks for your response. I am quite new to HealthKit.

    But yes the need for the immediate syncing stems to us needing to get a user's workout session/activity immediately after they press end on their Watch and send it to our app, then sending the activity data to our backend system for processing (there are some calculations our backend does for a user's fitness data) and that would need to reflect back on that app within a couple of minutes.

Add a Comment

Replies

It would be good to understand more of the use case/need for the immediate syncing... By default data from watch will sync to phone (if it's within range) when the workout completes so you could listen on the phone as well. Yes, enableBackgroundDelivery is the right API to be used. And it needs to be used in conjunction with HKObserverQuery. See the following

https://developer.apple.com/documentation/healthkit/hkobserverquerycompletionhandler

https://developer.apple.com/documentation/healthkit/hkobserverquery/executing_observer_queries

  • @Frameworks Engineer , thanks for your response. I am quite new to HealthKit.

    But yes the need for the immediate syncing stems to us needing to get a user's workout session/activity immediately after they press end on their Watch and send it to our app, then sending the activity data to our backend system for processing (there are some calculations our backend does for a user's fitness data) and that would need to reflect back on that app within a couple of minutes.

Add a Comment