I want to open location service screen programmatically to turn on service.
10 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
- 58,835
- 19
- 97
- 154
- 417
- 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
-
11This 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
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,016
- 2
- 26
- 34
-
2Easier: UIApplication.shared.openURL(URL.init(string: UIApplicationOpenSettingsURLString)!) – Tà Truhoada Dec 26 '17 at 04:36
-
@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
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,101
- 3
- 13
- 36
-
1
-
4
-
@MMSousa in IOS 11 `URL(string: "App-prefs:root=LOCATION_SERVICES")` still works without problems... – user25 Feb 13 '18 at 09:14
-
13As 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,030
- 31
- 37
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,225
- 3
- 23
- 50
-
@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,107
- 3
- 18
- 41
-
4Apple 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
-
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
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)
}
- 4,335
- 36
- 31
-
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
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
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,792
- 1
- 15
- 31
-
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