How to read Apple iOS 16 Heart Rate Zones from HealthKit

Is there way to read the Apple Heart rate zones from HealthKit? I want to read the min/max bpm for each of the 1-5 zones.

I went through the Apple HealthKit developer documentation but couldn't find it https://developer.apple.com/documentation/healthkit

There isn't a way to read Heart Rate Zones from HealthKit. You can submit a feedback request to provide such an API.

I've submit three past feedback (FB13879424 most recent) for this and mentioned it at three WWDC sessions.

🙏🙏 for a solution soon!

I want this too. Apple, we like making workout apps for your platform, clearly, you like to tell us each year how many health and fitness apps there are. Open up heart rate zone APIs and management with respect to workouts to third party developers. It has been a few years for you to stabilize the feature and internal API to make ready for public!

The speed of which Apple Fitness on iPhone can calculate heart rate zones is within a moment, at present, fetching all heart rate samples associated to a workout and computing the time in each zone is an order of seconds. Evidently, Apple is writing this data privately in HealthKit because you wouldn't be saving health and fitness data outside of HealthKit db, right?

FB15382945 - HealthKit: Give third party developers access to the internal heart rate zones recorded and associated with Activity app workouts

Years ago, I found via printing metadata on workouts saved by Apple's Activity app on Apple Watch that they were saving metadata keys and structures using _HKPrivateMetadata***. I have a feedback I wrote years ago about workout splits, but I can't find anything about heart rate zones, but it still feels familiar from the summer they introduced it.

For the time being, @ravdamani @simonfromhelix and any other third party developer, do you have interest in contributing to an open source 'third party metadata' keys swift package? The issue with metadata, custom keys that is, is other apps including Apple's Health app can't know about localization or appropriate meaning. For example, I allow my users to differentiate between canoeing and kayaking, and for the time being until Apple decides to split them into two different activity types (FB7807902 - June 2020). I wanted to use a key 'HKMetadataKeyPaddleSportsType' BUT, that doesn't localize at all and is confusing to users in other apps. I balanced this with usability for English by declaring the key name as 'Paddle Sports Type'. The first feedback below would mitigate that, but it isn't really in the spirit of sharing that Apple teaches health developers to follow. The second additional feedback is related to those private metadata. Just try saving any of these keys:

  • _HKPrivateMetadataSplitActiveDurationQuantity
  • _HKPrivateMetadataSplitDistanceQuantity
  • _HKPrivateMetadataSplitMeasuringSystem

Private API? No, it is a string value provided to a dictionary that should accept any string. Private Usage? Yes, this will crash your code at runtime.

Related:

FB15053061 - HealthKit: Allow third party developers to create hidden metadata that can only be read by apps that belong to the same TeamID that generated the sample

FB15052902 - HealthKit: Custom metadata keys are being rejected with an undocumented error

How to read Apple iOS 16 Heart Rate Zones from HealthKit
 
 
Q