Ron Barr
Ron Barr

Reputation: 391

HealthKit: Reading HKCorrelationType is not allowed

When I attempt to initialize HealthKit with an HKCorrelation sample type, the app crashes with 'Authorization to read the following types is disallowed: HKCorrelationTypeIdentifierBloodPressure'.

I've successfully read from a variety of quantity types and the sleep category types.

The code is not contiguous but I'm calling

[healthStore requestAuthorizationToShareTypes:writeDataTypes
                                    readTypes:readDataTypes
                                   completion:^(BOOL success, NSError *error) {
... 
}

where readDataTypes is an NSSet containing the set of sample types I am looking to read. One of them is HKCorrelationTypeIdentifierBloodPressure.

When I remove the blood pressure key from the set it works fine.

The set also includes HKQuantityTypeIdentifierBloodPressureSystolic and HKQuantityTypeIdentifierBloodPressureDiastolic sample types.

Does Apple not want us reading the combined data type?

Upvotes: 8

Views: 1805

Answers (1)

Dan Waylonis
Dan Waylonis

Reputation: 812

I've had success with asking for authorization of the individual elements of the blood pressure correlation:

HKQuantityType *bpSystolicType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodPressureSystolic];
HKQuantityType *bpDiastolicType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodPressureDiastolic];

And then when I want to query the samples:

HKSampleType *type = [HKQuantityType correlationTypeForIdentifier:HKCorrelationTypeIdentifierBloodPressure];

Upvotes: 15

Related Questions