beginNewActivity(configuration:date:metadata:)
Begins a new workout activity in the workout session.
Declaration
func beginNewActivity(configuration workoutConfiguration: HKWorkoutConfiguration, date: Date, metadata: [String : Any]?)Parameters
- workoutConfiguration:
The configuration information for the activity. For Swimbikerun workouts, the activity’s configuration must use the Swimming, Cycling, or Running activity types. For interval training, the activity’s configuration must use the same activity type as the containing workout.
- date:
The activity’s start date and time.
- metadata:
Metadata that provides additional information about the activity.
Mentioned in
Discussion
This method asynchronously creates a new workout activity. HealthKit calls the session delegate’s workoutSession(_:didBeginActivityWith:date:) method after the activity begins. If the workout already has a current activity, HealthKit also ends that activity.
HealthKit may also set the data source’s typesToCollect value based on the new activity. If you’ve never modified the types that the data source collects (for example, by calling enableCollection(for:predicate:) or disableCollection(for:)), HealthKit automatically sets the typesToCollect property to a set of relevant data types based on the new actiity. However, if you’ve explicitly set the collected data types, HealthKit won’t modify them; therefore, you may need to update them for the new activity.