Will it be possible to get heart rate readings only by Using Extended Runtime Sessions?

Our app uses HKWorkoutSession to measure user's heart rate during 2-min mindfulness test.


My got rejected multiple times due to unintended use of HKWorkoutSession. Apple review team suggested to use Extended Runtime Sessions instead of HKWorkoutSession.


I would like to know that, will it be possible to get heart rate readings only by Using Extended Runtime Sessions ? Kindly share me if any document regarding this.


The following link is unavailable to follow.

Extended Runtime for watchOS Apps
Session 251 (9min)
https://developer.apple.com/videos/play/wwdc2019/251/


Help me ASAP.

Replies

Hi. I realize it's been a few months since you asked this question, and might have already found an answer. However, if you have not, this is indeed possible. There are a couple of building blocks you need to put together to enable reading heart rate when using an extended runtime session, and not using a workout. All the links below contain code snippets to help you get started.
  • Obviously, extended runtime session. See

Using Extended Runtime Sessions
  • Optionally, if you need periodic updates, or updates that notify your app during background execution, use an observer query. When the observer query notifies your app that an update is available, your app needs to perform a sample query to actually retrieve the updated sample. See

Executing Observer Queries
  • When the heart rate HKQuantitySample is delivered to your app, it needs to be converted to a beats-per-minute value:

Code Block swift
// Counstruct the count per time unit.
let countUnit: HKUnit = .count()
let minuteUnit: HKUnit = .minute()
let beatsPerMinute: HKUnit = countUnit.unitDivided(by: minuteUnit)
// If this is a UI update, so dispatch to main.
DispatchQueue.main.async {
self.heartRate = sample.quantity.doubleValue(for: beatsPerMinute)
}

If your app plays audio during the entire time, then instead of an extended runtime session, and audio background session is more appropriate, and will give your app background processing while the audio plays. Please give putting together these building blocks a shot, and if you still need help with the implementation, file a technical support incident with DTS, so we can help you further.
Thank you so much for detailed guide. Let me try out. It will be helpful if you get me the following session, seems broken.

Extended Runtime for watchOS Apps
Session 251 (9min)
https://developer.apple.com/videos/play/wwdc2019/251/
I agree that by Using Extended Runtime Sessions + Executing Observer Queries i can get periodic updates of Heart Rate changes in iOS app.

We have an independant watchOS app. how can i do the same in watchOS?

FYI : We are running two mins meditation test in our watch app which requires background execution to capture HR change.
Hi. The above procedure should work on watchOS 6. Can I ask you for more detail about what is not working on watchOS?
I am using WKExtendedRuntimeSession + HKObserverQuery + HKSampleQuery to read heart rate.

Using Background Mode as Mindfulness. but my app stopped receiving HR once watch goes to sleep after 15 secs.

How do i get background HR updates in watchOS?

Is the following API only for iOS?
https://developer.apple.com/documentation/healthkit/hkhealthstore/1614175-enablebackgrounddeliveryfortype?language=objc

FYI: I got some insights from watchOS team during WWDC20 lab session. Kindly tag watchOS team to this thread. I have shared my sample code to DTS, Follow-up: 728122810, If it is really possible. Kindly check the code and check whats wrong.

Thanks