Is there documentation on how to read workout effort scores from a HealthKit workout? I'm interested in reading workoutEffortScore and estimatedWorkoutEffortScore. I have not been successful trying to read them using the same method that I do other workout HKQuantityTypes (heartRate, stepCount, etc). I'm using Swift and I do have authorization for those types requested and granted.
I have found documentation on setting these values (https://developer.apple.com/forums/thread/763539) but not reading them.
Thank You
I haven't checked .estimatedWorkoutEffortScore
yet, but for .workoutEffortScore
, if I related the sample correctly, as described in the mentioned post, the following code returns the right sample to me:
// let predicate = HKQuery.predicateForObjects(from: workout)
let predicate = HKQuery.predicateForSamples(withStart: workout.startDate, end: workout.endDate)
let query = HKSampleQuery(sampleType: HKQuantityType(.workoutEffortScore),
predicate: predicate,
limit: HKObjectQueryNoLimit,
sortDescriptors: []) { (_, results, error) in
print("\(String(describing: results?.first))")
}
healthStore.execute(query)
Using HKQuery.predicateForObjects(from: workout)
as the predicate for the query doesn't return anything to me, which does surprise me, given that the sample is correctly related to the workout. I’d suggest that you file a feedback report against that – If you do so, please share your report ID here.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.