How to detect if the user doesn't allow Apple Health Kit Authorisation?
Asked Answered
S

2

5

I am using AppleHealthKit in my application. Everything is working correctly. The problem is that I am not able to detect if the user taps "Don't Allow" button when asking for permission.

enter image description here

With this method, my application uses HealthKit, even though the user doesn't allow this.

requestAuthorizationToShareTypes(healthKitTypesToWrite, readTypes: healthKitTypesToRead) { (success, error) -> Void in
        if( completion != nil ) {
            completion(success:success,error:error)
        }

Apple Documentation:

enter image description here

So basically my question is how to detect this?

Sandor answered 6/8, 2016 at 7:59 Comment(0)
L
8

You cannot detect it, by design:

To help prevent possible leaks of sensitive health information, your app cannot determine whether 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.

(from HKHealthStore)

Labdanum answered 6/8, 2016 at 9:13 Comment(0)
H
5

You can do this but only for one specific type and only for write data(u can do the same with other type too if u have to check them)

HKHealthStore *_healthStore;
HKQuantityType *stepsType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];

HKAuthorizationStatus status = [_healthStore authorizationStatusForType:stepsType];

BOOL isActive;
switch (status) {
    case HKAuthorizationStatusSharingAuthorized:
        isActive = YES;
        break;
    case HKAuthorizationStatusSharingDenied:
        isActive = NO;
        break;
    case HKAuthorizationStatusNotDetermined:
        isActive = NO;
        break;

    default:
        break;
}

NSLog(@"STATUS-------%@", isActive ? @"yes" : @"no");
Heavily answered 8/6, 2017 at 12:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.