简体   繁体   English

HealthKit requestAuthorization为correlationType(forIdentifier:.bloodPressure)

[英]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 我正在尝试从HealthKit读取bloodPressure数据,我想知道为什么我必须要求使用.bloodPressureSystolic.bloodPressureDiastolic而不是.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) 其中dataTypesToRead = HKObjectType.correlationType(forIdentifier: .bloodPressure) (ps:这只是为了简单起见,应将correlationType(forIdentifier: )展开)

and the app crashes. 然后应用崩溃 So I am guessing that one cannot requestAuthorization for correlationType(forIdentifier: ) 所以我猜测,一个不能requestAuthorizationcorrelationType(forIdentifier: )

if I use HKObjectType.quantityType(forIdentifier:) or .categoryType(forIdentifier:) then requestAuthorization works perfectly, also with .bloodPressureSystolic and .bloodPressureDiastolic 如果我使用HKObjectType.quantityType(forIdentifier:).categoryType(forIdentifier:)requestAuthorization可以完美工作,也可以与.bloodPressureSystolic.bloodPressureDiastolic

If my guess is correct then why Apple says: 如果我的猜测是正确的,那么苹果为什么要说:

typesToRead A set containing the data types you want to read. typesToRead一组包含要读取的数据类型。 This set can contain any concrete subclass of the HKObjectType class (any of the HKCharacteristicType , HKQuantityType, HKCategoryType, HKWorkoutType or HKCorrelationType classes ). 此集合可以包含HKObjectType类的任何具体子类( HKCharacteristicType , HKQuantityType, HKCategoryType, HKWorkoutType or HKCorrelationType classes )。 If the user grants permission, your app can read these data types from the HealthKit store. 如果用户授予许可,则您的应用程序可以从HealthKit存储读取这些数据类型。

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

is my guess correct? 我的猜测正确吗? why I can't ask permission for HKObjectType.correlationType(forIdentifier: .bloodPressure) ?? 为什么我不能要求获得HKObjectType.correlationType(forIdentifier: .bloodPressure)许可?

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. HealthKit不需要关联类型的授权,因为您的应用只能查询与被授权读取的成员对象的关联。 It seems like the documentation is just a little misleading when it mentions HKCorrelationType classes. 当提到HKCorrelationType类时,该文档似乎有点误导。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM