Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Mobile / iPhone

Checking Location Service Permissions on iOS

4.50/5 (2 votes)
25 Oct 2013CPOL 13.2K  
Check whether location service enabled for your app.

Introduction

For iOS apps, users can decide which application uses location service. Therefore you have to check location services enabled for your app. It's very easy.

Using the code

First, we have to check whether location services enabled for generally use. Second, we have to check whether location services enabled for our app.

Like this:

Objective-C
if([CLLocationManager locationServicesEnabled]){
   NSLog(@"Location Services Enabled"); 
   if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){
      alert = [[UIAlertView alloc] initWithTitle:@"App Permission Denied" 
              message:@"To re-enable, please go to Settings and turn on Location Service for this app." 
              delegate:nil 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil];
      [alert show];
   }
}

That's all!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)