I can't get it working when using relateWorkoutEffortSample. The completion comes back without an error but there doesn't seem to be an effort stored for the workout when I view it in the Fitness app.
My code is:
HKUnit* effortUnits = [HKUnit appleEffortScoreUnit];
HKQuantity* effortQuantity = [HKQuantity quantityWithUnit:effortUnits doubleValue:effort];
HKQuantityType* effortQuantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierWorkoutEffortScore];
HKQuantitySample* effortSample = [HKQuantitySample quantitySampleWithType:effortQuantityType quantity:effortQuantity startDate:self.startDate endDate:self.endDate];
for (HKWorkoutActivity* activity in self.workout.workoutActivities)
[self.store relateWorkoutEffortSample:effortSample withWorkout:self.workout activity:activity completion:^(BOOL success, NSError * _Nullable error) {
if (!success)
{
if (error)
NSLog(@"Error saving effort score: %@", error.localizedDescription);
else
NSLog(@"Error saving effort score");
}
else
NSLog(@"Successfully saved effort score %d", effort);
}];