ios – HealthKit does not show exercise occasion names
[ad_1]
I need to write information to AppleHealth from my health app. So I create an HKWorkout pattern, and add exercise occasions there (e.g. Squat, Assisted dip, Barbell Curl).
Right here is the best way I create HKWorkoutEvent array
var workoutEvents = [HKWorkoutEvent]()
var metadata: [String: Any] = [:]
workoutEvents = exercise.workoutExercises.map {
metadata[HKMetadataKeyWorkoutBrandName] = $0.train.title
return HKWorkoutEvent(
sort: .phase,
dateInterval: DateInterval(begin: $0.timeStartedDate, period: 60.0 * 6),
metadata: metadata
)
}
And right here is the best way I create single HKWorkout occasion
let hkworkout = HKWorkout(
activityType: .traditionalStrengthTraining,
begin: startDate,
finish: endDateUsing,
workoutEvents: workoutEvents,
totalEnergyBurned: caloriesBurnt,
totalDistance: nil,
totalSwimmingStrokeCount: nil,
machine: .native(),
metadata: nil)
After which I save that exercise like this
HKHealthStore().save([hkworkout]) { success, error in }
My drawback is once I head to Apple Well being app, and skim data from my app, there are not any train names displayed. As a substitute I see solely “Section” phrase associated to every exercise, which may be very irritating for the person I suppose, as he would most likely wish to see which exercise he hung out on, and so on.
See screenshot hooked up beneath
So I suppose HKWorkoutEvent doesn’t learn information from HKMetadataKeyWorkoutBrandName
worth and units “phase” phrase for all of the exercise occasion.
Is there any technique to have precise exercise occasion title have displayed in Apple Well being?
[ad_2]