Workout mode drains battery heavily

I am building a watchOS app with iOS companion app.

The watch app needs to track the heart rate during the night or while user is sleeping. And the desired frequency of measurement is 0.2Hz (every 5 seconds)

For this I am using the HKWorkout mode with mindAndBody session.

While it works fine, One of the main issue is: after about 6-7 hours of usage, the battery on the watch drains between 40% (Series 9) and 100% (series 7, I think)

My questions:

  • Are there any other option to track user's heart rate without workout, while the app could be in background?
  • Another side effect of this workout mode is, Even if we choose not to save the workout in HealthKit, the Activity rings gets populated by this mindAndBody session, which makes it when the user is waking up, the bar is already full, This is not desired.

Is there any option to specify for ActivityRing skips this?

Highly appreciate any help in advance.

Cheers - Prakash

Answered by DTS Engineer in 818693022

How latest information could we get from Healthkit with this approach? We could still relax the frequency as low as 0.033 Hz (every 30 seconds).

You can use HKObserverQuery + enableBackgroundDelivery(for:frequency:withCompletion:) to have your app get notified (even in the background) when the HealthKit data you are observing changes, and your app can then fetch the latest data from there.

I don't have anything to share about how often the system samples the heart rate while the user sleeping, but you can start with grabbing the data from the HealthKit store, and see if that is good enough for your analysis.

Note that the HealthKit data an Apple Watch generates is only available on the paired iPhone after the HealthKit stores on both devices are synchronized, and so the data your iPhone app gets may have a delay because the HealthKit stores don't synchronize in real time.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Are there any other option to track user's heart rate without workout, while the app could be in background?

When running a workout (HKWorkout), the device increases the sampling frequency of its sensors, and so it isn't a surprise to me that the battery level was drained heavily in the case you described.

For sleep tracking, if you set up a sleep schedule and turn on sleep tracking on your Apple Watch, the watch will track your sleep and put the relevant health data (including heart rate) into the HealthKit store. Your app can then access the data with HealthKit and do sleep analysis based on that.

Does this path work for you? If not, I'll be curious why it doesn't, and also why you need to measure the heart rate every 5 seconds.

Another side effect of this workout mode is, Even if we choose not to save the workout in HealthKit, the Activity rings gets populated by this mindAndBody session, which makes it when the user is waking up, the bar is already full, This is not desired.

I believe this is an as-designed behavior. The activity rings try to reflect the activities that really happened, and are not a statistics of the data in HealthKit. When using your Apple Watch, you might have noticed that even you don’t start any workout, the rings still move over time, and that is because the sensors detect the activities.

Having said that, I do know that Fitness.app allows a user to delete a workout, which also deletes the associated minutes and calories represented in the Activity Rings. If that is what you are looking for, I'd suggest that you file a feedback report for the HealthKit team to consider. If you do so, please share your report ID. I'd be happy to route it directly to the team.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Thanks for the response.

Multiline BlockQuote For sleep tracking, if you set up a sleep schedule and turn on sleep tracking on your Apple Watch, the watch will track your sleep and put the relevant health data (including heart rate) into the HealthKit store. Your app can then access the data with HealthKit and do sleep analysis based on that. Does this path work for you? If not, I'll be curious why it doesn't, and also why you need to measure the heart rate every 5 seconds.

Our app needs to measure the heart rate every 5 seconds in order to track the sleep stage of the user and our companion iOS app will "assist" user accordingly for uninterrupted sleep.

Using the sleep data from HealthKit could still be interesting for us as long as we get the data in time.

How latest information could we get from Healthkit with this approach? We could still relax the frequency as low as 0.033 Hz (every 30 seconds).

The only reason we use workout mode is to get the heart rate even when the app goes in background mode. Is. there any other option to achieve this?

Thanks for the suggestion about Fitness.app. That would be useful too. But with the large battery drain, the primary goal is to find alternates to workout.

Thanks a ton for your time. I have been stuck on this for a bit now. Any further pointers would be greatly helpful.

Accepted Answer

How latest information could we get from Healthkit with this approach? We could still relax the frequency as low as 0.033 Hz (every 30 seconds).

You can use HKObserverQuery + enableBackgroundDelivery(for:frequency:withCompletion:) to have your app get notified (even in the background) when the HealthKit data you are observing changes, and your app can then fetch the latest data from there.

I don't have anything to share about how often the system samples the heart rate while the user sleeping, but you can start with grabbing the data from the HealthKit store, and see if that is good enough for your analysis.

Note that the HealthKit data an Apple Watch generates is only available on the paired iPhone after the HealthKit stores on both devices are synchronized, and so the data your iPhone app gets may have a delay because the HealthKit stores don't synchronize in real time.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Thanks very much Ziqiao Chen 🙏.

I will make a prototype and see how often we can get this.

Workout mode drains battery heavily
 
 
Q