Instance Method

start(_:)

Starts a workout session for the current app.

Declaration

func start(_ workoutSession: HKWorkoutSession)

Parameters

workoutSession

The workout session to start. You cannot restart a workout session that has stopped. If you pass in a session that is running or has stopped, the system returns an invalidArgumentException exception.

Discussion

Workout sessions allow apps to run in the foreground. The current Foreground App appears when the user wakes the watch. Additionally, Apple Watch sets its sensors based on the workout activity and location types for more accurate measurements and better performance.

Apple Watch can only run one workout session at a time. If a second workout is started while your workout is running, your HKWorkoutSessionDelegate object receives an HKErrorAnotherWorkoutSession error, and your session ends.

This method returns immediately, however the work is performed asynchronously on an anonymous serial background queue. If successful, the session’s state transitions to HKWorkoutSessionState.running, and the system calls the session delegate’s workoutSession(_:didChangeTo:from:date:) method.

See Also

Managing Workout Sessions

func startWatchApp(with: HKWorkoutConfiguration, completion: (Bool, Error?) -> Void)

Launches or wakes the Watch app to create a new workout session.

func pause(HKWorkoutSession)

Pauses the provided workout session.

Deprecated
func resumeWorkoutSession(HKWorkoutSession)

Resumes the provided workout session.

Deprecated
func end(HKWorkoutSession)

Ends a workout session for the current app.

Deprecated