How do I determine if a user is authorized by the Apple Health Kit?

I am using AppleHealthKit in my application. Everything is working correctly. The problem is that I can’t determine if the user removes the "Do not allow" button when asking for permission.

enter image description here

Using this method, my application uses HealthKit , even if the user does not 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?

+4
source share
2 answers

You cannot find it, by design:

, , . , , HealthKit .

( HKHealthStore)

+5

, (u , )

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");
+4

Source: https://habr.com/ru/post/1650395/


All Articles