Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-enabling location services for iPhone app

I have been struggling with the location service request for my iPhone app. If the user says "Don't allow", I'm stuck in my "this app needs location services in order to work"...

All attempts to re-apply for location services have been fruitless, which several stacks here can testify to.

Then I read that the only way to re-enable the location services was to redirect the user to the location service settings using this :

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]]; 

But even that doesn't seem to work (iPhone 4 and 4S, both on 5.1)

Is there really no other way, except telling the user to go to preferences and then guiding him through ? It seems so toe-twistingly bulky to me.

like image 263
Nils Munch Avatar asked Nov 03 '22 21:11

Nils Munch


1 Answers

If the user turned the location service off, there is no other way then to tell the user to turn them on again.

You could try to redirect, but this is only possible on iOS 5.0. So you can do it like:

NSURL *prefsURL = [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];

if ([[UIApplication sharedApplication] canOpenURL:prefsURL]) {
   [[UIApplication sharedApplication] openURL:prefsURL];
} else {
  // Can't redirect user to settings, display alert view
  UIAlertView *alertView = ....

}
like image 149
rckoenes Avatar answered Nov 15 '22 06:11

rckoenes