Matteo Girardi
Matteo Girardi

Reputation: 45

HealthKit requestAuthorization for correlationType(forIdentifier: .bloodPressure)

I am trying to read bloodPressure data from HealthKit and I wonder why I have to ask for .bloodPressureSystolic and .bloodPressureDiastolic instead of .bloodPressure

What I am trying to do is asking

requestAuthorization(toShare: nil, read: dataTypesToRead, completion: { ... })

where dataTypesToRead = HKObjectType.correlationType(forIdentifier: .bloodPressure) (ps: this is just for simplicity, correlationType(forIdentifier: ) should be unwrapped)

and the app crashes. So I am guessing that one cannot requestAuthorization for correlationType(forIdentifier: )

if I use HKObjectType.quantityType(forIdentifier:) or .categoryType(forIdentifier:) then requestAuthorization works perfectly, also with .bloodPressureSystolic and .bloodPressureDiastolic

If my guess is correct then why Apple says:

typesToRead A set containing the data types you want to read. This set can contain any concrete subclass of the HKObjectType class (any of the HKCharacteristicType , HKQuantityType, HKCategoryType, HKWorkoutType or HKCorrelationType classes). If the user grants permission, your app can read these data types from the HealthKit store.

https://developer.apple.com/documentation/healthkit/hkhealthstore/1614152-requestauthorization

is my guess correct? why I can't ask permission for HKObjectType.correlationType(forIdentifier: .bloodPressure) ??

Upvotes: 1

Views: 700

Answers (1)

Allan
Allan

Reputation: 7353

HealthKit doesn't require authorization for correlation types because your app can only query for correlations with member objects that it is authorized to read. It seems like the documentation is just a little misleading when it mentions HKCorrelationType classes.

Upvotes: 2

Related Questions