Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 213
iranjith4 Avatar asked Mar 16 '15 12:03

iranjith4


1 Answers

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.

like image 81
Allan Avatar answered Nov 11 '22 04:11

Allan