iosswifthealthkithkhealthstore

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


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?


Solution

  • 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)