What is the frequency at which you can access data with your app in background?

I’m trying to understand how often I can get updates on stuff like Heart Rate , Oxygen Saturation and movement.

I'm building a third party app that detects sleep phases so I need it to monitor all night (5-8 hours) and get an update at least every minute.

I don’t think I can use the HKWorkoutType class/subclass since it’s not really a workout, and I was told Apple might reject my application.

I understand I should be able to get something via enableBackgroundDelivery

Another post here suggests to use ExtendedRuntimeSessions

Can anyone give me some directions on the feasibility? Is there any way to access Heart Rate directly, without using the WorkoutSession classes?

PS What about movement? Is accessing the accelerometer easier?

Accepted Reply

Do you really need live updates every minute? More likely you want data from when the user was asleep, but not continuous monitoring. You can use a background observer query, which will provide the app with ~4-15 seconds of runtime every hour to process the data you're observing, if it has changed.

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

  • Hey thanks for your reply! Yeah, I do need live updates. I need to be able to detect REM sleep through an algorithm I developed that requires movement, heart rate and oxigen saturation. So yes, I could wait for the watch to signal the user is asleep to begin monitoring, but then I will need relatively continuous monitoring. One thing I was thinking to try was: When asleep do a check, if certain conditions are met, continue monitoring, otherwise do another check in 5 minutes. If conditions are met, do continuous monitoring for a while, in order to determine if you are in REM or not.

    Thanks for the link, I will look into it. If my explanation bring out other ideas, I'll look into them as well!

  • @Frameworks Engineer, can I access Accelerometer data and Oxigen Saturation using Observer Queries? Will the -15 second updates be able to include records of the data second by second?

Add a Comment

Replies

Do you really need live updates every minute? More likely you want data from when the user was asleep, but not continuous monitoring. You can use a background observer query, which will provide the app with ~4-15 seconds of runtime every hour to process the data you're observing, if it has changed.

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

  • Hey thanks for your reply! Yeah, I do need live updates. I need to be able to detect REM sleep through an algorithm I developed that requires movement, heart rate and oxigen saturation. So yes, I could wait for the watch to signal the user is asleep to begin monitoring, but then I will need relatively continuous monitoring. One thing I was thinking to try was: When asleep do a check, if certain conditions are met, continue monitoring, otherwise do another check in 5 minutes. If conditions are met, do continuous monitoring for a while, in order to determine if you are in REM or not.

    Thanks for the link, I will look into it. If my explanation bring out other ideas, I'll look into them as well!

  • @Frameworks Engineer, can I access Accelerometer data and Oxigen Saturation using Observer Queries? Will the -15 second updates be able to include records of the data second by second?

Add a Comment