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 !
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.
Go to Settings > Privacy > Location Services. Make sure that Location Services is on.
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.
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.
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)
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.
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];
}
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