I want to open location service screen programmatically to turn on service.
12 Answers
I have tried all the above answers,it's not working on iOS11..it just opens settings page and not the app settings .. Finally this works..
UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!)
Swift 4.2:
UIApplication.shared.open(URL(string:UIApplication.openSettingsURLString)!)
Refer: https://developer.apple.com/documentation/uikit/uiapplicationopensettingsurlstring?language=swift

- 62,602
- 20
- 102
- 156

- 457
- 4
- 6
-
6Yes. Avoid use of "prefs:root" or "App-Prefs:root" in you app, otherwise App will be rejected from App Store. Just open Setting page. – Gurjinder Singh Aug 06 '18 at 06:12
-
14This will open your app setting in Settings app, not the 'Location Services' . – Rohit Chauhan Jul 31 '19 at 07:55
-
It went to the 'Location Services' for me! – Ahmadreza Aug 25 '19 at 17:23
-
I just saw that tinder takes you directly to the screen location services. How do they do that? Been searching through all the internet. – Iván Yoed Feb 22 '23 at 09:11
Swift 4.2
Go straight to YOUR app's settings like this:
if let bundleId = Bundle.main.bundleIdentifier,
let url = URL(string: "\(UIApplication.openSettingsURLString)&path=LOCATION/\(bundleId)")
{
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

- 3,626
- 2
- 31
- 40
-
2Easier: UIApplication.shared.openURL(URL.init(string: UIApplicationOpenSettingsURLString)!) – Tà Truhoada Dec 26 '17 at 04:36
-
2@TàTruhoada it's useless if Location services are disabled, what you wrote here it's for app location permission but not for enable/disable locations services itself.. you can't change location permissions for your app if location services itself are disabled – user25 Feb 13 '18 at 09:27
-
4As of May 25, 2018 our app got rejected because of using prefs:root under Guideline 2.5.1 - Performance - Software Requirements – Ted May 26 '18 at 07:05
-
question asks about going to the location services page not the app settings page – F.O.O May 15 '21 at 04:08
-
1I just saw that tinder takes you directly to the screen location services. How do they do that? Been searching through all the internet. – Iván Yoed Feb 22 '23 at 09:12
-
Although it's not the precise answer (Monika asked about system services) but it's exactly the answer that I was looking for! – kelin Aug 15 '23 at 11:49
You can open it directly like using below code,
But first set URL Schemes
in Info.plist's URL Type Like:
Then write below line at specific event:
In Objective - C :
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
In Swift :
UIApplication.sharedApplication().openURL(NSURL(string: "prefs:root=LOCATION_SERVICES")!)
Hope this will help you.

- 3,189
- 3
- 14
- 38
-
1
-
4
-
@MMSousa in IOS 11 `URL(string: "App-prefs:root=LOCATION_SERVICES")` still works without problems... – user25 Feb 13 '18 at 09:14
-
15As of May 25, 2018 our app got rejected because of using prefs:root under Guideline 2.5.1 - Performance - Software Requirements – Ted May 26 '18 at 07:05
Do you want to be safe? use UIApplicationOpenSettingsURLString
, which will open the app settings, without deep-link.
Using App-prefs
your app will be rejected, as many sub comments said.
https://github.com/mauron85/cordova-plugin-background-geolocation/issues/394

- 4,440
- 34
- 37
Swift 5+
Easy Way Direct Your said application page will open
if let BUNDLE_IDENTIFIER = Bundle.main.bundleIdentifier,
let url = URL(string: "\(UIApplication.openSettingsURLString)&path=LOCATION/\(BUNDLE_IDENTIFIER)") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

- 5,361
- 1
- 43
- 34
-
please share the error message why its reject my app is still live with this code – Shakeel Ahmed Jun 18 '20 at 17:46
-
Guideline 2.5.1 Performance - Software Requirements Your app uses the "prefs:root=" non-public URL scheme, which is a private entity. The use of non-public APIs is not permitted on the App Store because it can lead to a poor user experience should these APIs change. Specifically, your app uses the following non-public URL scheme app-prefs:root=privacy&path=location Continuing to use or conceal non-public APIs in future submissions of this app may result in the termination of your Apple Developer account, as well as removal of all associated apps from the App Store – Andrey Jun 19 '20 at 09:38
-
https://stackoverflow.com/questions/50040558/ios-app-store-rejection-your-app-uses-the-prefsroot-non-public-url-scheme – Shakeel Ahmed Jun 19 '20 at 13:39
First:
Add URL
Go to Project settings --> Info --> URL Types --> Add New URL Schemes
See image below:
Second:
Use below code to open Location settings:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
referred from: https://stackoverflow.com/a/35987082/5575752

- 1
- 1

- 5,335
- 3
- 24
- 51
-
@Joe Susnick Do you have a solution for iOS 10? Thanks for any help – Erich Brunner Jun 27 '17 at 01:29
-
1@EricBrunner yes, I posted above but the url: ```App-Prefs:root=Privacy&path=LOCATION``` worked for me. – Joe Susnick Jun 27 '17 at 18:11
-
@Joe Susnick Great. Do I have to distinquish between iOS 8,9 and 10.x or does that work in all versions? Thanks again for your support! – Erich Brunner Jun 27 '17 at 18:22
-
@EricBrunner I've only tested it on 10 but I'm pretty confident it'll work on 9. As far as 8 goes, not sure. – Joe Susnick Jun 28 '17 at 16:39
-
4As of May 25, 2018 our app got rejected for using prefs:root under Guideline 2.5.1 - Performance - Software Requirements – Ted May 26 '18 at 07:06
Step 1: Click on project name >> target>> info >> url Types
Step 2:
-(IBAction)openSettingViewToEnableLocationService:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
}

- 2,287
- 3
- 20
- 45
-
5Apple prohibits the use of this API now, you might not want to use it anymore since it may lead to rejection by app review: https://stackoverflow.com/questions/49059668/appstore-rejection-performance-software-requirements-prefsroot-graphicsser – MartijndeM May 25 '18 at 10:27
-
1
If you set locationManager.startUpdatingLocation() and you have disabled on your iphone, it automatically show you an alertView with the option to open and activated location.

- 31
- 2
-
This worked exactly one time. It was the first time I tried. Does iOS remembers in any way what option I choose? I know `startUpdatingLocation()` showed me a standard dialog to navigate to the location service settings. And it navigated into the system wide location service settings! But it did that only the first time I called it. Any idea on this? – this.myself Jun 11 '20 at 13:39
-
To reply to previous comment, Apple documentation clearly states that this popup can only be shown ONCE per app lifetime. If you want it to re-appear, you need to restart the app. There are no way to work around this :( – SkyzohKey Jul 14 '21 at 10:12
This solution works for me, but I didn't know App Store will reject my app or not
if let bundleId = Bundle.main.bundleIdentifier,
let url = URL(string: "\(UIApplication.openSettingsURLString)&root=Privacy&path=LOCATION/\(bundleId)") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

- 318
- 3
- 14
Actually there's much simpler solution to that. It'll show your app settings with loction services/camera access, etc.:
func showUserSettings() {
guard let urlGeneral = URL(string: UIApplicationOpenSettingsURLString) else {
return
}
UIApplication.shared.open(urlGeneral)
}

- 105
- 1
- 2
-
2you can't enable location and change permission for your app if location services itself are disabled in system, so first you have to enable location services (see screenshot from author question) – user25 Feb 13 '18 at 09:05
Eureka: Forget about URLs. Use the method requestWhenInUseAuthorization
from the CLLocationManager
code to open the native prompt message. This is what Tinder and other apps do. Took me a while to figure it out.
This will open a prompt to take you EXACTLY to the Location Services screen:
let locationManager = CLLocationManager()
locationManager.requestWhenInUseAuthorization()

- 3,878
- 31
- 44
-
This doesn't seem to do anything if the user has previously disallowed location permissions for the app. From what I can find, this is only supposed to work until the user has made a choice about the location services permissions for the app. – David Rector May 25 '23 at 20:26
-
If he explicitly did so, yes, I think you're right. But if it's the first time he's been asked, I think this should work, even before making a choice, but I could be wrong. In general, after the user decides he does not want to give permission, the only thing left for the app to do is let him know he has to manually enable permissions again. Tinder and other famous apps do that that way too. – Iván Yoed May 26 '23 at 02:39
-
The point was that this doesn't always work as described. Once the user has made a permission choice, this no longer does anything visible in the app. Even uninstalling the app and reinstalling it won't always change the behavior since the system caches the user permission settings for the app. – David Rector Jun 01 '23 at 18:58
-
I see. You have a point. Do you think it's nonetheless useful to leave this answer here? Otherwise I maybe should delete it. – Iván Yoed Jun 01 '23 at 22:09
-
1The answer is useful. It just needed the extra little detail about not always showing the question to the user. – David Rector Jun 02 '23 at 00:06
After adding prefs as a url type, use the following code to go directly to the location settings of an application.
if let url = URL(string: "App-prefs:root=LOCATION_SERVICES") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

- 1,870
- 1
- 18
- 32
-
4As of May 25, 2018 our app got rejected because of this under Guideline 2.5.1 - Performance - Software Requirements – Ted May 26 '18 at 07:04
-
2@Ted even our app got rejected due to this. Do you know alternative to this? or workaround to get this working ? help would be appreciated – Srinivas Guni May 31 '18 at 06:18