Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I detect location service disable for my app?

IOS4 has recently introduced the possibility to enable/disable location services for a specific application.

I need to detect if this settings is enabled/disabled for MY application.

First I have tried with:

if ([CLLocationManager locationServicesEnabled])
    {
       ....
    } 

however this refers to the global location service and not to the specific application setting.

Second I have tried to use

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
   ...
} 

It works but it gets called both in case of service app setting disabled and in other cases like, for example, if a measure fails for some reasons.

I need a code to detect if MY application is allowed to use location services.

How can i achieve this?

Thanks for your support

like image 261
Massimo Avatar asked Sep 30 '10 13:09

Massimo


People also ask

Can an app track you if Location Services are off?

The answer is yes, it's possible to track mobile phones even if location services are turned off. Turning off the location service on your phone can help conceal your location. This is important if you don't want third parties knowing where you are or being able to track your movement.


2 Answers

From the documentation for locationManager: didFailWithError:

If the user denies your application’s use of the location service, this method reports a kCLErrorDenied error. Upon receiving such an error, you should stop the location service.

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    if ([[error domain] isEqualToString: kCLErrorDomain] && [error code] == kCLErrorDenied) {
        // The user denied your app access to location information.
    }
}

You can find the other error codes here.

like image 170
Kris Markel Avatar answered Nov 02 '22 05:11

Kris Markel


I prefer to use

-(BOOL)locationAuthorized {
  return ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized);
}

over the locationServicesEnabled property as it refers to the phone level, not your application.

like image 45
Joe Avatar answered Nov 02 '22 04:11

Joe