简体   繁体   English

HealthKit 授权状态始终为 1

[英]HealthKit Authorisation Status is always 1

I am using HealthKit in my app.我在我的应用程序中使用 HealthKit。 I am getting the Permission from the user for accessing the HealthKit Data.我正在从用户那里获得访问 HealthKit 数据的权限。 After the Authorisation, if I check for authorised status for a particular HealthKit Object type, it always returns that the access is denied.授权后,如果我检查特定 HealthKit 对象类型的授权状态,它总是返回访问被拒绝。 (1 is the enum integer Value). (1 是枚举整数值)。

Here is my code这是我的代码

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

The method [self.healthStore authorizationStatusForType:[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth]] always throws me 1 .方法[self.healthStore authorizationStatusForType:[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth]]总是抛出我1 Need help on this ?需要帮助吗?

The authorization status for an HKObjectType does not reflect whether your application has authorization to read samples of those types. HKObjectType 的授权状态不反映您的应用程序是否有权读取这些类型的样本。 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.因此,如果您的应用请求授权读取步数样本但未写入它们,并且用户授予读取授权,则 HKQuantityTypeIdentifierStepCount 的授权状态将为 HKAuthorizationStatusSharingDenied。

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.如果您没有获得许可,它只会显示为 HealthKit 存储中没有请求类型的数据。 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.来自其他来源的数据仍然隐藏。

NSArray *readTypes = @[[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierFlightsClimbed],[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning],[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]];

[self.healthStore requestAuthorizationToShareTypes:nil
                                         readTypes:[NSSet setWithArray:readTypes] completion:nil];

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

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