65.9K
CodeProject is changing. Read more.
Home

Checking Location Service Permissions on iOS

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.50/5 (2 votes)

Oct 25, 2013

CPOL
viewsIcon

13170

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:

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!