Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if Location Services is On or not?

How can I check if the user has turned off Location Services ?

So that I can prompt him/her to turn it On in order to use my app.

Thank you !

like image 845
nosuic Avatar asked Feb 06 '11 15:02

nosuic


People also ask

How do I know if my Location Services are on?

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.

How do you check if Location Services are enabled IOS?

Go to Settings > Privacy > Location Services. Make sure that Location Services is on.

Should I keep Location Services on or 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. However, a smartphone can still be tracked through other techniques that reveal its general location.

How do I turn on Location Services on my iPhone?

You can turn Location Services on or off at Settings > Privacy > Location Services. You can turn Location Services on either during the Setup Assistant process or later through the Location Services setting. You can individually control which apps and system services have access to Location Services data.


3 Answers

The CLLocationManager provides class methods to determine the availability of location services:

- (BOOL)locationServicesEnabled (for < iOS 4.0)

+ (BOOL)locationServicesEnabled (for iOS 4.0 and greater)

+ (CLAuthorizationStatus)authorizationStatus (for iOS 4.2+)

(and others, see documentation)

like image 51
Felix Avatar answered Oct 09 '22 11:10

Felix


If your application absolutely cannot run without Location Services, then you can make Location Services a requirement for installing/running your app using the app's Info.plist. You do this by adding the UIDeviceCapabilities key to your app's Info.plist and giving it a corresponding value of "location-services" minus the quotes.

With the Info.plist configured this way, if Location Services are turned off, or if the device is in airplane mode, or anything else is preventing the use of Location Services on the device, iOS will prompt the user to turn on Location Services when the app is opened.

EDIT: Brief experimentation seems to indicate that iOS does not prompt the user in this circumstance, so this would not be a good solution for you.

For more information, you can look at the Information Property List Key Reference section of Apple's developer documentation.

like image 28
Anthony Williams Avatar answered Oct 09 '22 10:10

Anthony Williams


Use the below piece of code...

  if (![CLLocationManager locationServicesEnabled]) {


    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];

}
like image 23
shankar Avatar answered Oct 09 '22 12:10

shankar