Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if location services are enabled for a particular app prior to iOS 4.2?

How can I check if the user has allowed location for mu app? Normally I would use authorizationStatus method of the CLLocationManager class, but it is only available in iOS 4.2 and newer. Is it possible to achieve this somehow while still using SDK 4.2, so that the app can still run on devices with older versions of iOS, or do I have to downgrade the SDK? And along the same line, I need a similar alternative for the locationServicesEnabled method prior to iOS 4.0.

like image 742
pajevic Avatar asked Jan 15 '11 17:01

pajevic


People also ask

How do you check if Location Services are enabled IOS?

The user can enable or disable location services from the Settings app by toggling the Location Services switch in General. You should check the return value of locationServiceEnabled() method before starting location updates to determine whether the user has location services enabled for the current device.

How do I enable Location Services for an app?

Open your phone's Settings app. Under "Personal," tap Location access. At the top of the screen, turn Access to my location on or off.

Why is Location Services disabled on my iPhone?

In the Settings app, tap Privacy, then tap Location Services. Make sure Location Services is on, and make sure Maps is set to While Using the App or Widgets. Set the date, time, and time zone correctly on your device.


2 Answers

When you call -startUpdatingLocation, if location services were denied by the user, the location manager delegate will receive a call to -locationManager:didFailWithError: with the kCLErrorDenied error code. This works both in all versions of iOS.

like image 52
Martin Gordon Avatar answered Oct 01 '22 05:10

Martin Gordon


I've combined two techniques in the code below

    MKUserLocation *userLocation = map.userLocation;     BOOL locationAllowed = [CLLocationManager locationServicesEnabled];     BOOL locationAvailable = userLocation.location!=nil;      if (locationAllowed==NO) {         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Service Disabled"                                                          message:@"To re-enable, please go to Settings and turn on Location Service for this app."                                                         delegate:nil                                                cancelButtonTitle:@"OK"                                                otherButtonTitles:nil];         [alert show];         [alert release];     } else {         if (locationAvailable==NO)              [self.map.userLocation addObserver:self forKeyPath:@"location" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:nil];     } 
like image 28
EasyCoder Avatar answered Oct 01 '22 05:10

EasyCoder