HealthKit授权状态始终为1 [英] HealthKit Authorisation Status is always 1

查看:738
本文介绍了HealthKit授权状态始终为1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用HealthKit。我从用户那里获得了访问HealthKit数据的权限。
授权后,如果我检查特定HealthKit对象类型的授权状态,它将始终返回拒绝访问。 (1是枚举整数值)。

I am using HealthKit in my app. I am getting the Permission from the user for accessing the HealthKit Data. After the Authorisation, if I check for authorised status for a particular HealthKit Object type, it always returns that the access is denied. (1 is the enum integer Value).

这是我的代码

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

方法 [self.healthStore authorizationStatusForType:[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth]] 总是抛出 1 。需要帮助吗?

The method [self.healthStore authorizationStatusForType:[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth]] always throws me 1. Need help on this ?

推荐答案

HKObjectType的授权状态并不反映您的应用程序是否具有 阅读 这些类型的样本。它仅表示您是否已经请求授权以及您的应用是否有权 编写 这些类型的样本。因此,如果您的应用程序请求授权读取步骤计数样本但不写入它们,并且用户授予读取授权,则HKQuantityTypeIdentifierStepCount的授权状态将为HKAuthorizationStatusSharingDenied。

The authorization status for an HKObjectType does not reflect whether your application has authorization to read samples of those types. It only indicates whether you have requested authorization at all and whether your app is authorized to write samples of those types. So if your app requests authorization to read step count samples but not write them, and the user grants read authorization, then the authorization status for HKQuantityTypeIdentifierStepCount will be HKAuthorizationStatusSharingDenied.

以下来自 HealthKit框架参考并解释了为什么您的应用可能无法查询其是否具有读取权限:

The following is from the HealthKit framework reference and explains why your app may not query whether it has read access:


帮助防止敏感健康信息可能泄漏,您的
应用程序无法确定用户是否已授予
读取数据的权限。如果您未获得许可,则只显示
,HealthKit商店中没有所请求类型的数据。如果您的
应用程序获得了共享权限但未获得读取权限,则您只能看到应用程序已写入商店的数据
。其他
来源的数据仍然隐藏。

To help prevent possible leaks of sensitive health information, your app cannot determine whether or not a user has granted permission to read data. If you are not given permission, it simply appears as if there is no data of the requested type in the HealthKit store. If your app is given share permission but not read permission, you see only the data that your app has written to the store. Data from other sources remains hidden.

这篇关于HealthKit授权状态始终为1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆