0

I am showing the user location on a mapView with:

self.mapView.showsUserLocation = YES;

The user gets prompted the AlertView where he can choose whether to allow to use the current location or not. If he presses yes everything is ok and I do not worry about it.

But if he presses NO I would like to zoom to a specific region.

So how do I know whether the MKMapView is allowed to use the current location?

I found the solution where I would create my own CLLocationManager and its delegate to see if it returns an denied error. But this does not quite feel right, why introduce a new CLLocationManger if I do not need it.

Isn't there an other way?

BObereder
  • 1,046
  • 1
  • 13
  • 29
  • 1
    Have you checked the `CLLocationManager Class Reference`? There're several lines of text telling that you should use `authorizationStatus` method of CLLocationManager class – Stas Dec 17 '12 at 10:35

1 Answers1

3

You don't need a delegate. Just use the CLLocationManager class method authorizationStatus:

if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized) {
    // allowed
} else {
    // not allowed
}

The possible values are:

typedef enum {
   kCLAuthorizationStatusNotDetermined = 0,
   kCLAuthorizationStatusRestricted,
   kCLAuthorizationStatusDenied,
   kCLAuthorizationStatusAuthorized
} CLAuthorizationStatus;
DrummerB
  • 39,814
  • 12
  • 105
  • 142
  • exactly what I needed! Thank you! I was so fixed on that delegate thing I did not even think about this solution!. – BObereder Dec 17 '12 at 10:53