Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

Recording a HeartbeatSeries

I need to be able to create and store a HeartbeatSeries for a given time-period from an Apple Watch, to then retrieve that data from HealthKit to be processed.

I have working code which allows me to begin a workout session, which is being used to determine how long a session has been running for. I also have working code for retrieving HeartbeatSeries data from HealthKit. The issue is that no HeartbeatSeries data is being stored into HealthKit as a result of the workout session running. Whether that session is running for as little as 30 seconds or as long as 20 minutes, nothing is stored.

However, when I use the the Apple "Meditation" app (formerly known as "Breathe"), I can query HealthKit afterwards and retrieve a list of individual heartbeat timings during that 2 minute period. Therefore, it IS possible to store a HeartbeatSeries from within an app on the Apple Watch.

What I would like to know is, how can I use the pulse sensor built-in to the Apple Watch to be able to record a HeartbeatSeries similar to how the Meditation app does it.

Answered by DTS Engineer in 830840022

There is no API that provides direct access to the pulse sensor built-in to the Apple Watch, but with HealthKit, you should be able to retrieve the heartbeat series in the following way:

  1. Use the start date, end date, and sample type (HKSeriesType.heartbeat()) to query the heartbeat series samples (HKHeartbeatSeriesSample) in the HealthKit store.

  2. Use HKHeartbeatSeriesQuery to access the underlying beat-to-beat measurements for a HKHeartbeatSeriesSample sample.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

There is no API that provides direct access to the pulse sensor built-in to the Apple Watch, but with HealthKit, you should be able to retrieve the heartbeat series in the following way:

  1. Use the start date, end date, and sample type (HKSeriesType.heartbeat()) to query the heartbeat series samples (HKHeartbeatSeriesSample) in the HealthKit store.

  2. Use HKHeartbeatSeriesQuery to access the underlying beat-to-beat measurements for a HKHeartbeatSeriesSample sample.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

This is the approach we are already using to query HealthKit for the the HeartbeatSeries stored in there. I need some way of now creating a HeartbeatSeries over a given time period, in much the same way that the Meditation app does. Would you know the approach that the Meditation app uses to accomplish this, or would you be able to suggest an alternative?

I am not in the position to comment how Meditations.app does that, but as far as I know, there is currently no API for 3rd party apps to trigger on-demand heartbeat series on an Apple Watch; there is no API to access the heartbeat raw data from the Apple Watch either. I'd hence suggest that you file a feedback report with your concrete use case – If you do so, please share your report ID here.

We do have HKHeartbeatSeriesBuilder that can create heartbeat series, but since you can't get the raw data from an Apple Watch, the API is pretty much to be used with other heatbeat monitors.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Recording a HeartbeatSeries
 
 
Q