iosswifthealthkithkhealthstore

HealthKit requestAuthorization(toShare:, read, completion: ) : is there are way to know whether it was promped at least once?


I am currently working with HealthKit and I am wondering: is it possible to know whether the requestAuthorization has been previously asked?


Solution

  • Based on the documentation, it appears not. You can ask for authorization status for a particular HKObjectType, but this will only tell you if can save data of that type. You can't tell whether read access has been granted. According to the docs:

    To help prevent possible leaks of sensitive health information, your app cannot determine whether or not a user has granted permission to read data.

    You can call requestAuthorization repeatedly, and the user will only be prompted if they have not previously granted access to the HKObjectType's requested:

    If the user has already chosen to grant or prohibit access to all of the types specified, the completion is called without prompting the user.