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.
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 QueriesCode 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.