I want to add segments into running HKWorkout.
As i understand i should use addWorkoutEvents method on my HKWorkoutBuilder.
So my code is
func saveSegment(forStep step: GymWorkoutEventStep) {
let dateInterval = DateInterval(start: step.startDate ?? Date(), end: Date())
let metadata = [
HKMetadataKeyWasUserEntered: true
]
let event = HKWorkoutEvent(type: .segment, dateInterval: dateInterval, metadata: metadata)
builder?.addWorkoutEvents([event], completion: { success, error in
print(success ? "Success saving segment" : error.debugDescription)
})
}
I'm trying to implement same feature like in Apple Watch app "Workout" when we can switch to next segment on double tap. So my code works, i can see in console "Success saving segment". But then, when i'm finishin workout, Fitness app doesn't show Segments section at all. What i'm missing? And how to add distance, pace to each segment, because i can't see any MetadataKey's for it?
