Tested on iOS 9.2
To get location updates, we should always check
- Location services are enabled on the user's iOS device and
- Application-specific location properties
and launching the user on the correct settings screen to enable
Launch iOS device location settings page
Step .1 Go to project settings → Information → URL types → Add new URL schemes

Step 2. Use the code below to launch the direct phone settings page: (Note: URL scheme is different in iOS 10+, we check the version as indicated here )
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) //Usage NSString* url = SYSTEM_VERSION_LESS_THAN(@"10.0") ? @"prefs:root=LOCATION_SERVICES" : @"App-Prefs:root=Privacy&path=LOCATION"; [[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]];

Launch the application location settings page
Use the code below to launch the direct application location settings page
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

Here is an example of the complete code: #define SYSTEM_VERSION_LESS_THAN (v) ([[[[UIDevice currentDevice] systemVersion] compare: v options: NSNumericSearch] == NSOrderedAscending)
CLLocationManager *locationManager; -(void) checkLocationServicesAndStartUpdates { locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyBest; if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [locationManager requestWhenInUseAuthorization]; } //Checking authorization status if (![CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled!" message:@"Please enable Location Based Services for better results! We promise to keep your location private" delegate:self cancelButtonTitle:@"Settings" otherButtonTitles:@"Cancel", nil]; //TODO if user has not given permission to device if (![CLLocationManager locationServicesEnabled]) { alertView.tag = 100; } //TODO if user has not given permission to particular app else { alertView.tag = 200; } [alertView show]; return; } else { //Location Services Enabled, let start location updates [locationManager startUpdatingLocation]; } }
Contact the customer responsible for the request and run the correct location settings.
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if(buttonIndex == 0)//Settings button pressed { if (alertView.tag == 100) { //This will open ios devices location settings NSString* url = SYSTEM_VERSION_LESS_THAN(@"10.0") ? @"prefs:root=LOCATION_SERVICES" : @"App-Prefs:root=Privacy&path=LOCATION"; [[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]]; } else if (alertView.tag == 200) { //This will opne particular app location settings [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; } } else if(buttonIndex == 1)//Cancel button pressed. { //TODO for cancel } }
swiftBoy Mar 14 '16 at 8:42 on 2016-03-14 08:42
source share