SangamAngre SangamAngre - 1 year ago 88
iOS Question

How to detect user selects Don't Allow for MKMapView for iphone

I have created a application which uses mapview. For maps I used

library. Everything works fine when user selects "Allow" button on alert window. But I want to detect when user selects "Don't Allow". I found a delegate which most of the developers used

(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error

but the delegate does not get called.

Maybe I am missing something. In my header (.h) file I have implemented
. Is there anything else I need to do?

Do I need to add some extra classes like
or else.


Answer Source

In order to monitor the changes in the authorization status for the location services you need to implement the CLLocationManagerDelegate method locationManager:didChangeAuthorizationStatus: obtaining something like

-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {

    if (status == kCLAuthorizationStatusDenied) {
        // permission denied
    else if (status == kCLAuthorizationStatusAuthorized) {
        // permission granted

For a complete list of the possible authorization statuses and their description you can check out the official documentation of CLAuthorizationStatus.


You probably have already your instance of CLLocationManager, let's call it locationManager. Then in order to implement your delegate you conform your class to the CLLocationManagerDelegate protocol (you can declare it in the header of class -- this is not mandatory but it will provide you some static checking facilities) and assign it to the delegate property of locationManager like follows:

locationManager.delegate = self; //assuming that self is gonna be the delegate

If you did everything as explained your controller will be called at every authorization change, as stated by the documentation:

this method is called whenever the application’s ability to use location services changes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download