A quantity sample type that measures the user’s heart rate.
SDKs
- iOS 8.0+
- Mac Catalyst 13.0+
- watchOS 2.0+
Framework
- Health
Kit
Declaration
static let heartRate: HKQuantity Type Identifier
Discussion
These samples use count/time units (described in HKUnit
) and measure discrete values (described in HKStatistics
).
Heart rate samples may include motion context information, which is stored as metadata using the HKMetadata
key. The value of this key is an NSNumber
object that contains a HKHeart
value.
The motion context gives additional information about the user’s activity level when the heart rate sample was taken. Apple Watch uses the following guidelines when setting the motion context:
If the user has been still for at least 5 minutes prior to the sample, the context is set to the
HKHeart
value.Rate Motion Context .sedentary If the user is in motion, the context is set to the
HKHeart
value.Rate Motion Context .active
You can add motion context to the metadata of any heart rate samples that you create. This means other apps may also save heart rate samples with (or without) the HKMetadata
metadata key.
Note that not all heart rate samples have a motion context. For example, if Apple Watch cannot determine the motion context, it creates samples without a HKMetadata
metadata key. In addition, heart rate samples recorded by an Apple Watch (1st generation) or by a device running watchOS 3 or earlier do not have the motion context metadata key. Treat these samples as if they used the HKHeart
motion context.