Skip to content

Instantly share code, notes, and snippets.

@danlipert
Created September 12, 2011 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danlipert/1212671 to your computer and use it in GitHub Desktop.
Save danlipert/1212671 to your computer and use it in GitHub Desktop.
iOS location services denial handling
/* found on stack overflow: http://stackoverflow.com/questions/3401757/locationservicesenabled-test-passes-when-they-are-disabled-in-viewdidload
also: http://stackoverflow.com/questions/2333344/how-to-handle-dont-allow-for-location-manager
*/
- (void)locationManager: (CLLocationManager *)manager
didFailWithError: (NSError *)error {
NSString *errorString;
[manager stopUpdatingLocation];
NSLog(@"Error: %@",[error localizedDescription]);
switch([error code]) {
case kCLErrorDenied:
//Access denied by user
errorString = @"Access to Location Services denied by user";
//Do something...
break;
case kCLErrorLocationUnknown:
//Probably temporary...
errorString = @"Location data unavailable";
//Do something else...
break;
default:
errorString = @"An unknown error has occurred";
break;
}
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment