Eugene Gordin
Eugene Gordin

Reputation: 4107

How to request authorization for Health Kit when needed?

In my app I'm integrating Apple HealthKit support. I figured how to request authorization for the different types.

However, if user goes to Health app, and changes authorization for all those types back to NO, my app is not able to use any data. Calling requestAuthorizationToShareTypes again doesn't bring Health viewController with the options again.

I found the post on stackoverflow, where it was suggested to change the types, which will trick Health app to open its authorization view again. It actually works.

Is there any less tricky and more reasonable ways to do it?

Any kind of help is highly appreciated!

Upvotes: 1

Views: 1687

Answers (1)

David Berry
David Berry

Reputation: 41246

Check if access is allowed using authorizationStatusForType, and, if not allowed, present an alert informing the user that permission is required and offering to take them to the settings page to fix it.

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
   [[UIApplication sharedApplication] openURL:url];
}

Upvotes: 2

Related Questions