In the settings -> general, there is a switch to turn on/off the location services. In the Maps app, when location services is off, if the user click on the find me button, it pops up an alert and asks the user to turn on location servi开发者_JAVA百科ces in the settings. It then exits the app and launch the settings app. How can I do that programmatically in my app?
As of iOS 5.0 you can open the settings app programmatically using the "prefs://" URL scheme. You are out of luck on earlier versions.
If you just use location services by [CLLocationManager startUpdatingLocation] it will automatically pop up the alert you describe if Location Services are disabled.
However, there's no way to force showing the alert when your specific app has been rejected from using location services by the user (in iOS 4 by disabling your app in the location settings, in iOS 3 by denying the CoreLocation request at the first 2 starts of the app). You only receive the kCLErrorDenied error in -locationManager:didFailWithError:.
Maps.app does show the alert with a Settings button in this case but it looks like they're using a private API for that.
I didn't finish reading the whole question!
However, see: Programmatically opening the settings app (iPhone)
(Original reply: The Settings app doesn't seem to have a custom URL scheme, so it appears that the answer is "no".)
精彩评论