Class

HKWorkoutSession

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

Declaration

@interface HKWorkoutSession : NSObject

Overview

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 HKErrorAnotherWorkoutSessionStarted error, and your session ends.

Topics

Creating Workout Sessions

- initWithHealthStore:configuration:error:

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

Monitoring the Session

delegate

The workout session’s delegate.

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

- associatedWorkoutBuilder

Returns the live workout builder associated with the workout session.

Managing the Workout

- prepare

Prepares the workout session.

- startActivityWithDate:

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

- pause

Pauses the workout session.

- resume

Resumes the workout session.

- stopActivityWithDate:

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

- end

Ends the workout session.

Accessing Session Data

endDate

The ending time and date for this workout session.

startDate

The starting time and date for this workout session.

state

The workout session’s current state.

workoutConfiguration

The configuration object that describes this workout.

Deprecated Methods

- initWithActivityType:locationType:

Returns a newly instantiated workout session.

Deprecated
- initWithConfiguration:error:

Returns a newly instantiated workout session.

Deprecated
activityType

The workout activity performed during this session.

Deprecated
locationType

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

Deprecated

Relationships

Inherits From

Conforms To

See Also

Sessions

Running Workout Sessions

Track a workout on Apple Watch.

HKWorkoutConfiguration

An object that contains configuration information about a workout session.

HKWorkoutSessionState

A workout session’s state.

HKLiveWorkoutBuilder

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

HKLiveWorkoutDataSource

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