Hello,
In my application, I need to obtain precise workout segment data from HKWorkout in order to calculate per-kilometer metrics such as heart rate and pace.
My current approach is:
1.Use HKWorkout to fetch the associated HKWorkoutEvents.
2.Take the end time of one event as the start time of the next event to derive per-kilometer segment ranges.
The issue I’m facing:
•If a user sets Apple Watch to notify every 5 kilometers, then at 5 km, 10 km, 15 km, etc., I see overlapping event times.
•From the HKWorkoutEvents data alone, I cannot distinguish between events that represent “per-kilometer splits” and those that represent “5-kilometer notifications.”
•As a result, my per-kilometer heart rate and pace calculations can be inaccurate.
My question is:
Is there a recommended way to reliably differentiate per-kilometer splits from custom distance notifications and ensure accurate segment data retrieval?
For example, should I instead reconstruct segments using HKWorkoutRoute and distance samples, rather than relying on HKWorkoutEvents?
STEPS TO REPRODUCE
1.On Apple Watch, start an Outdoor Run using the Workout app.
2.In workout notifications, set distance alerts to every 5 kilometers.
3.During the run, when reaching 5 km, 10 km, 15 km, etc., the watch triggers notifications.
4.Query the corresponding HKWorkout from HealthKit and inspect its HKWorkoutEvents.
5.Notice that some event start times are duplicated, and it is unclear which events represent “per-kilometer splits” and which represent “5-kilometer notifications.”
Expected Result:
Be able to differentiate between per-kilometer splits and custom distance alerts, so that heart rate and pace per kilometer can be calculated accurately.
Actual Result:
The HKWorkoutEvents data contains duplicated event times without a way to distinguish event types, leading to inaccurate per-kilometer statistics.