Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

ios - HealthKit Authorisation Status is always 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).

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. Need help on this ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...