Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have created a application which uses mapview. For maps I used MKMapKit 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 MKMapViewDelegate. Is there anything else I need to do?

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

Thanks,

like image 438
SangamAngre Avatar asked Dec 17 '12 08:12

SangamAngre


2 Answers

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.

EDIT

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.

like image 93
Gabriele Petronella Avatar answered Nov 15 '22 11:11

Gabriele Petronella


Can you try this:

if(![CLLocationManager locationServicesEnabled])
{
    // alert location services denied
}
like image 37
Zhang Avatar answered Nov 15 '22 11:11

Zhang