Learn about Workouts and workout sessions in HealthKit.
- [Narrator] So let's talk a little bit about workouts. A workout is data that represents a physical activity. This typically includes the activity type, the duration of the workout, distance that you've moved during the workout, and energy burned. Samples are other data that are not necessarily contained within a workout, but can be queried using a workout, so they're associated. The HKWorkout Class is the class that we'd use for creating a workout.
It doesn't need a specific type identifier to create. You must provide an HKWorkoutActivityType value for each workout which defines which kind of workout it is. Some examples are archery, yoga, stairs, and other values. Workout samples can contribute to move and exercise rings on your watch. You use a workout session on the watch to track a user's activity. HKWorkoutSession is the class that you would use to create, stop, and start workout sessions.
This is only available on the Apple Watch. When you create a workout session, it fine tunes the Apple Watch's sensors for the specific activity that you've chosen and it's important to note that workout sessions generate higher frequency heart rate sampling so you'll get more data when you use a workout session. To manage sessions, you'll use the HKHealthStore to create, start, and end your workout session. Once the workout session has ended, you'll save a workout with that session.
Then you'll associate any data that you've collected during the workout.
- Creating a HealthKit-enabled project
- Authorizing HealthKit on an Apple Watch and iPhone
- Creating a workout on an Apple Watch
- Creating workout sessions
- Saving a workout to HealthKit
- Creating a query
- Displaying workout data on an iPhone
- Creating an Activity summary query
- Displaying an Activity ring on an Apple Watch and iPhone