Akash Shah
Akash Shah

Reputation: 11

How to check Status whether HealthKit permissions have been granted

I want to check if HeathKit has been authorized for me to read the user's data, if I'm authorized segue to the workouts, if not pop an alert. But requestAuthorizationToShareTypes always seems to return true? How can I get a reference to whether the user has authorized me or not?

Upvotes: 1

Views: 1861

Answers (1)

Paulw11
Paulw11

Reputation: 115076

You cannot find out whether the user has authorised access or not

From the documentation

To help protect the user’s privacy, your app doesn’t know whether the user granted or denied permission to read data from HealthKit. If the user denied permission, attempts to query data from HealthKit return only samples that your app successfully saved to the HealthKit store.

You can query to determine if the user has already responded to a request for access to a set of health kit types. If you get HKAuthorizationRequestStatusUnnecessary then you have already asked for permission. If you get HKAuthorizationRequestStatusShouldRequestyou should request permission.

If you query for workouts and get none, you should display a message indicating that no workouts were found either because the user has no created any workout items or they need to check permissions along with instructions on checking permissions in the settings app.

Upvotes: 3

Related Questions