Reputation: 11
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
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 HKAuthorizationRequestStatusShouldRequest
you 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