12

If locationServicesEnabled return false, I'm prompting the user to enable their Location Services. The following URL works for 10.0+, redirecting the user to the Settings app and directly to the Location Services screen:

URL(string: "App-Prefs:root=Privacy&path=LOCATION")

However this doesn't work in iOS 11. It opens the Settings app, but doesn't drill down to the Location Services. Anyone knows what's the new URL for iOS 11+?

zeus
  • 12,173
  • 9
  • 63
  • 184

3 Answers3

5

Apple published a list of URLs which they explicitly allow at this link. Unfortunately if you use other URLs (such as the one you are trying to use) this can get your app rejected from the App Store.

Short answer: You cannot do what you are trying to do without breaking the App Store rules.

ehmjaysee
  • 157
  • 10
3

In iOS 15 this wasn't working for me, as it was just opening the general settings page, but based on shivi_shub answer and his comment I tried the following:

if let bundleId = Bundle.main.bundleIdentifier,
   let url = URL(string: "\(UIApplication.openSettingsURLString)&path=LOCATION_SERVICES/\(bundleId)")
{
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

And it brought me to the location settings, which at least is a couple steps closer to the settings page I really want to show.

So I guess we could just do:

if let url = URL(string: "\(UIApplication.openSettingsURLString)&path=LOCATION_SERVICES") {
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
jdev
  • 569
  • 5
  • 25
2

Use this-

UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!)

Using App-prefs may lead to the rejection of the app on app store.

Or you can try this also-

if let bundleId = Bundle.main.bundleIdentifier,
let url = URL(string: "\(UIApplication.openSettingsURLString)&path=LOCATION/\(bundleId)") {
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
shivi_shub
  • 1,018
  • 1
  • 7
  • 15
  • but i want to open the general settings tab of the location (where it is deactivated), not the settings tab of my app :( – zeus Sep 12 '18 at 19:21
  • Try to change the url as -- URL(string: "App-prefs:root=LOCATION_SERVICES") – shivi_shub Sep 12 '18 at 19:37
  • no not work under ios 11 :( did you make it working ? – zeus Sep 12 '18 at 20:31
  • 2
    `if let url = URL(string:UIApplicationOpenSettingsURLString) { UIApplication.shared.open(url) }` – SwiftArchitect Nov 19 '18 at 20:42
  • 1
    The solution proposed by SwiftArchitect works partially - it successfully opens the system Settings App, but the OP question was specifically how to open a subsection of Settings, i.e., Location, General, or Privacy. The previous url extensions, like "root=General" do not work in iOS 12 – BlueskyMed Nov 29 '18 at 15:51