WorkoutKit
Create, preview, and sync workout compositions to the Workout app.
Overview
The WorkoutKit framework provides models and utilities for creating and previewing workouts in your iOS and watchOS apps, and for syncing scheduled workouts to the Workout app on Apple Watch. The framework supports the following types of workouts:
- CustomWorkout
A structured interval workout with a series of steps containing custom goals and alerts
- SingleGoalWorkout
A workout with a single goal, such as distance, energy, or time
- PacerWorkout
A workout with distance and time goals
- SwimBikeRunWorkout
A workout that allows triathletes to seamlessly transition between swim, bike, and run activities
You define a workout by initializing one of these workout types. Then you use the workout to create a WorkoutPlan, which provides methods for previewing, syncing, or exporting the plan. To open the plan in Workout on Apple Watch, call openInWorkoutApp(). To export the plan, call the dataRepresentation(as:) method.
You can also use WorkoutKit to create and maintain a workout schedule and, with the user’s permission, sync scheduled compositions to Apple Watch. These compositions appear in a dedicated space in the Workout app and include your app’s icon and name.
Before you can schedule a workout, you must ask for permission. Get the shared WorkoutScheduler instance, and call its requestAuthorization() method. Then call the schedule(_:at:) method to schedule workouts.
To access health data for the workout, see the HealthKit framework.