I understand why, but the ambiguity of the errors that HealthKit releases is a complete black box. Why am I getting the error message:
An error occurred while adding the sample to the training: the operation could not be completed.
I searched the web for examples, but most of them are quick .:(
Here is my code:
- (NSSet *)dataTypesToRead { HKQuantityType *heartRate = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate]; return [NSSet setWithObjects:heartRate, nil]; } - (NSSet *)dataTypesToWrite { HKWorkoutType* workout = [HKWorkoutType workoutType]; HKQuantityType *energyBurnedType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierActiveEnergyBurned]; return [NSSet setWithObjects:workout, energyBurnedType, nil]; } - (void)saveWorkout { HKHealthStore* healthStore = [[HKHealthStore alloc] init]; NSDate* timeOfWorkout = [NSDate date]; HKWorkoutType* type = [HKWorkoutType workoutType]; [healthStore requestAuthorizationToShareTypes:[self dataTypesToWrite] readTypes:[self dataTypesToRead] completion:^(BOOL success, NSError *error) { if(success == YES) {
source share