ira*_*th4 11 objective-c ios healthkit
我在我的应用程序中使用HealthKit.我从用户那里获得了访问HealthKit数据的权限.在授权之后,如果我检查特定HealthKit对象类型的授权状态,它总是返回拒绝访问.(1是枚举整数值).
这是我的代码
// Steps
if ([self.healthStore authorizationStatusForType:[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]] == HKAuthorizationStatusSharingAuthorized) {
[self accessStepsFrom:fromDate to:toDate];
}
//Sleep
if ([self.healthStore authorizationStatusForType:[HKObjectType categoryTypeForIdentifier:HKCategoryTypeIdentifierSleepAnalysis]] == HKAuthorizationStatusSharingAuthorized) {
[self accessSleepFrom:fromDate to:toDate];
}
//DOB
if ([self.healthStore authorizationStatusForType:[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth]] == HKAuthorizationStatusSharingAuthorized) {
[self accessDOB];
}
Run Code Online (Sandbox Code Playgroud)
这种方法[self.healthStore authorizationStatusForType:[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth]]
总是让我失望1
.需要帮助吗?
All*_*lan 32
HKObjectType的授权状态不反映您的应用程序是否有权读取这些类型的样本.它仅表示您是否已请求授权以及您的应用是否有权编写这些类型的样本.因此,如果您的应用程序请求授权读取步骤计数样本但不写入它们,并且用户授予读取授权,则HKQuantityTypeIdentifierStepCount的授权状态将为HKAuthorizationStatusSharingDenied.
以下内容来自HealthKit框架参考,并解释了为什么您的应用可能无法查询它是否具有读取权限:
为了帮助防止敏感健康信息可能泄漏,您的应用无法确定用户是否已授予读取数据的权限.如果您未获得许可,则看起来好像HealthKit商店中没有所请求类型的数据.如果您的应用获得了共享权限但未获得读取权限,则只会看到应用已写入商店的数据.来自其他来源的数据仍然隐藏.