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,
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.
Can you try this:
if(![CLLocationManager locationServicesEnabled])
{
// alert location services denied
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With