A session that tracks the user’s workout on Apple Watch.


class HKWorkoutSession : NSObject


The session finetunes Apple Watch’s sensors for the specified activity. All workout sessions generate high-frequency heart rate samples; however, an outdoor cycling activity generates accurate location data, while an indoor cycling activity does not.

Apple Watch runs one workout session at a time. If a second workout starts while your workout is running, your HKWorkoutSessionDelegate object receives an HKError.Code.errorAnotherWorkoutSessionStarted error, and your session ends.


Creating Workout Sessions

init(healthStore: HKHealthStore, configuration: HKWorkoutConfiguration)

Returns a newly instantiated workout session with an associated workout builder.

Monitoring the Session

var delegate: HKWorkoutSessionDelegate?

The workout session’s delegate.

protocol HKWorkoutSessionDelegate

The session delegate protocol defines an interface for receiving notifications about errors and changes in the workout session’s state.

Accessing the Workout Builder

func associatedWorkoutBuilder() -> HKLiveWorkoutBuilder

Returns the live workout builder associated with the workout session.

Managing the Workout

func prepare()

Prepares the workout session.

func startActivity(with: Date?)

Starts the workout session activity, and sets the start date.

func pause()

Pauses the workout session.

func resume()

Resumes the workout session.

func stopActivity(with: Date?)

Stops the workout session activity, and sets the end date.

func end()

Ends the workout session.

Accessing Session Data

var endDate: Date?

The ending time and date for this workout session.

var startDate: Date?

The starting time and date for this workout session.

var state: HKWorkoutSessionState

The workout session’s current state.

var workoutConfiguration: HKWorkoutConfiguration

The configuration object that describes this workout.

Deprecated Methods

init(configuration: HKWorkoutConfiguration)

Returns a newly instantiated workout session.

var activityType: HKWorkoutActivityType

The workout activity performed during this session.

var locationType: HKWorkoutSessionLocationType

A value that indicates whether the workout session occurred indoors or outdoors.



Inherits From

See Also


Running Workout Sessions

Track a workout on Apple Watch.

SpeedySloth: Creating a Workout

Use the Workout Builder API to start, stop, and to save workouts on Apple Watch.

class HKWorkoutConfiguration

An object that contains configuration information about a workout session.

enum HKWorkoutSessionState

A workout session’s state.

class HKLiveWorkoutBuilder

A builder object that constructs a workout incrementally based on live data from an active workout session.

class HKLiveWorkoutDataSource

A data source that automatically provides live data from an active workout session.