Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prompt the user to turn on location services after user has denied their use

I have an application with an explicit user interaction that makes use of the user's current location. If the user denies access to location services, I would still like subsequent uses to prompt the user to go to settings and re-enable location services for my app.

The behavior I want is that of the built-in Maps app:

  1. Reset location warnings in Settings > General > Reset > Reset Location Warnings.
  2. Start Maps app.
  3. Tap Current Location button in lower left corner.
  4. Maps prompts with ""Maps" Would Like to Use Your Current Location" | "Don't Allow" | "Allow".
  5. Choose "Don't Allow" option.
  6. Tap Current Location button in lower left corner again.
  7. Maps prompts with "Turn On Location Services to Allow "Maps" to Determine Your Location" | "Settings" | "Cancel".

In my own app, the same basic flow results in my CLLocationManagerDelegate -locationManager:didFailWithError: method being called with a kCLErrorDenied error at the final step and the user is not given the option to open the Settings app to correct it.

I could display my own alert in response to the error, but it would not have the ability to launch the Settings app like the alert that the OS can provide as used by the built-in Maps app.

Is there something in the CLLocationManager class I am missing that would be able to give me this behavior?

like image 678
GBegen Avatar asked Feb 03 '11 21:02

GBegen


People also ask

How do I ask for location permissions in IOS?

To request authorization, call requestWhenInUseAuthorization or requestAlwaysAuthorization , depending on the authorization status your app needs. See Choosing the Location Services Authorization to Request for more information about deciding what type of authorization to request.

How do I unblock location services?

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.


1 Answers

With iOS8, you can finally link user to Settings app via openURL. For example, you can create a UIAlertView with a single button that takes user to the Settings app:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:ICLocalizedString(@"LocationServicesPermissionTitle")                                                     message:ICLocalizedString(@"LocationPermissionGeoFenceMessage")                                                    delegate:self                                           cancelButtonTitle:@"Settings"                                           otherButtonTitles:nil];     [alert show]; 

In your UIAlertView delegate:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {     [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];     [[UIApplication sharedApplication] openURL: [NSURL URLWithString: UIApplicationOpenSettingsURLString]]; } 
like image 138
mobileideafactory Avatar answered Oct 09 '22 07:10

mobileideafactory