1

I have determined authorization before actually trying to save any data or do anything with it. The error is happening at the moment of query:

HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:foodType 
predicate:predicate 
limit:HKObjectQueryNoLimit 
sortDescriptors:nil 
resultsHandler:^(HKSampleQuery *query, NSArray *results, NSError *error){ ... }

Yes, I have read apple documentation that says:

Attempts to save data before permission has been requested fail with a HKErrorAuthorizationNotDetermined error.

But I do request permissions before I try to ask for data (I see the list with all data types (in the code - dataTypesToRead / Write)). Did anybody have this type of issue?

Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
Async-
  • 3,140
  • 4
  • 27
  • 49

1 Answers1

2

Ok, found out the problem. In the data types when identifying which types of data can the app read and write I had the wrong type for Sleep analysis.

Wrong:

HKCategoryType *sleepType = [HKSampleType categoryTypeForIdentifier:HKCategoryValueSleepAnalysisAsleep];

Right:

HKCategoryType *sleepType = [HKSampleType categoryTypeForIdentifier:HKCategoryTypeIdentifierSleepAnalysis];
Async-
  • 3,140
  • 4
  • 27
  • 49