Apple Health Kit Error Domain=com.apple.healthkit Code=5 "Authorization not determined"

4k views Asked by At

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?

1

There are 1 answers

0
Async- On BEST ANSWER

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];