Article

Using Workout Samples

Record a physical activity using workout samples.

Overview

An illustration showing how a workout is created and added to the store.

Although workouts are saved as HKWorkout samples, they behave somewhat differently than other sample types.

  • You do not need a specific type identifier to create the HKWorkoutType instance. All workouts use the same type identifier.

  • You must provide an HKWorkoutActivityType value for each workout. This value defines the type of activity performed during the workout.

  • After the workout is saved to the HealthKit store, you must associate additional samples with the workout (for example, active energy burned or distance samples). These samples provide fine-grained details about the workout. For more information, see HKWorkout.

Workout samples can contribute to the Move and Exercise rings in the Activity app. To contribute, you must associate one or more active energy burned samples with the workout. Additionally:

  • In watchOS. Use a workout session to track the user’s activity. When the session has ended, create a workout object and the associated active energy burned samples. For more information, see HKWorkoutSession.

    The system updates the Move ring based on the active energy burned samples. It updates the Exercise ring based on the amount of time the user spent actually exerting themselves during the workout session, as calculated by the watch’s sensors.

  • In iOS 10 or later. No additional work is necessary. Workout objects automatically contribute to both the Move and Exercise rings. The Exercise ring is increased by the workout’s total duration, and the Move ring is increased by the number of calories in the associated active energy burned samples. HealthKit also increases the Stand ring by one hour for each wall-clock hour that the workout overlaps.

  • In iOS 9. Workout objects saved on iPhone do not contribute to the activity rings.

Create and save workouts on the device that makes the most sense for your application. This will typically be the device that is running the logic for the user's workout.

Filling the Rings

Workout samples can contribute to the Move and Exercise rings in the Activity app. To contribute, you must associate one or more active energy burned samples with the workout. Additionally:

  • In watchOS. Use a workout session to track the user’s activity. When the session has ended, create a workout object and the associated active energy burned samples. For more information, see HKWorkoutSession.

    The system updates the Move ring based on the active energy burned samples. It updates the Exercise ring based on the amount of time the user spent actually exerting themselves during the workout session, as calculated by the watch’s sensors.

  • In iOS 10 or later. No additional work is necessary. Workout objects automatically contribute to both the Move and Exercise rings. The Exercise ring is increased by the workout’s total duration, and the Move ring is increased by the number of calories in the associated active energy burned samples. HealthKit also increases the Stand ring by one hour for each wall-clock hour that the workout overlaps.

  • In iOS 9. Workout objects saved on iPhone do not contribute to the activity rings.

Create and save workouts on the device that makes the most sense for your application. This will typically be the device that is running the logic for the user's workout.

See Also

Samples

HKWorkout

A workout sample stores information about a single physical activity.

HKWorkoutBuilder

A builder object that incrementally constructs a workout.

HKWorkoutType

A type that identifies samples that store information about a workout.

HKWorkoutTypeIdentifier

The workout type identifier.

HKWorkoutActivityType

The type of activity performed during a workout.

HKWorkoutEvent

An object representing an important event during a workout.