Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prompt user to turn on Location Services...again

I want to have the same functionality as the Map app, where user is prompted every time they press the 'current location' button to turn on their Location Services if they are off:

  • Turn off location services
  • User presses 'getCurrentLocation' button
  • App tries to get location using CLLocationManager
  • User gets 'Turn On Location Services..." message that shows "Settings" and "Cancel" buttons.
  • User taps 'Cancel'
  • User presses ''getCurrentLocation' button again
  • App tries to get location using CLLocationManager again
  • User does not get 'Turn On Location Services..." message any more

In the Map app, the user gets "Turn On Location Services..." message every time. How can I get my app to do the same? I made user I am using a new instance of CLLocationManager, in case that was the problem, but it was not. I can't see any settings that would affect this.

If I make my own Alert I cannot get the same 'Settings' button functionality. Also, I don't want the user to see multiple Alerts that look the same.

Any ideas?

like image 327
toofah Avatar asked May 13 '11 22:05

toofah


People also ask

How do I restart 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.

Can Location Services turn off on their own?

When either device spends a while not being connected to WiFi (for instance, when camping), the Location Services turn off on their own.

Why can'ti see someone's location after they shared it with me?

It's probably a problem with your friend's phone The most likely problem, for example, is that the other iPhone might not have cellular or WiFi reception. In addition, that other phone could be turned off, or your friend might have turned off location services in Settings.


2 Answers

New in iOS 8 there is a constant called UIApplicationOpenSettingsURLString.

From the "What's new in iOS" document under UIKit is the line:

You can take the user directly to your app-related settings in the Settings app. Pass the UIApplicationOpenSettingsURLString constant to the openURL: method of the UIApplication class.

From Apple's documentation:

UIApplicationOpenSettingsURLString

Used to create a URL that you can pass to the openURL: method. When you open the URL built from this string, the system launches the Settings app and displays the app’s custom settings, if it has any.

You can pass this into the UIApplication openURL: method. It might look something like:

NSURL *settings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

if ([[UIApplication sharedApplication] canOpenURL:settings])
    [[UIApplication sharedApplication] openURL:settings];
like image 110
Aaron Wasserman Avatar answered Sep 20 '22 13:09

Aaron Wasserman


If you want to point the user back to the Location Services screen in the Settings app, you can do so by sending them to a special URL, like so:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"prefs:root=LOCATION_SERVICES"]];
like image 42
Jacob White Avatar answered Sep 18 '22 13:09

Jacob White