How to open Location services screen from setting screen?
Asked Answered
B

12

65

I want to open location service screen programmatically to turn on service.

enter image description here

Boanerges answered 6/6, 2016 at 9:40 Comment(0)
B
3

Step 1: Click on project name >> target>> info >> url Types

enter image description here

Step 2:

-(IBAction)openSettingViewToEnableLocationService:(id)sender
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
}
Boanerges answered 6/6, 2016 at 10:8 Comment(2)
Apple prohibits the use of this API now, you might not want to use it anymore since it may lead to rejection by app review: #49060168Executrix
App Rejected by Apple.Qintar
T
41

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

Tortious answered 22/5, 2018 at 5:18 Comment(4)
Yes. Avoid use of "prefs:root" or "App-Prefs:root" in you app, otherwise App will be rejected from App Store. Just open Setting page.Arellano
This will open your app setting in Settings app, not the 'Location Services' .Crocodile
It went to the 'Location Services' for me!Cleaver
I just saw that tinder takes you directly to the screen location services. How do they do that? Been searching through all the internet.Cipolin
L
17

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)
}
Liberate answered 24/8, 2017 at 4:30 Comment(6)
Easier: UIApplication.shared.openURL(URL.init(string: UIApplicationOpenSettingsURLString)!)Nipha
@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 disabledVariorum
As of May 25, 2018 our app got rejected because of using prefs:root under Guideline 2.5.1 - Performance - Software RequirementsCarminacarminative
question asks about going to the location services page not the app settings pageSerenata
I just saw that tinder takes you directly to the screen location services. How do they do that? Been searching through all the internet.Cipolin
Although it's not the precise answer (Monika asked about system services) but it's exactly the answer that I was looking for!Insincere
A
9

You can open it directly like using below code,

But first set URL Schemes in Info.plist's URL Type Like:

enter image description here

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.

Arlenaarlene answered 6/6, 2016 at 10:7 Comment(4)
After implementing it will it pass App Store review guidelines?Aspidistra
in iOS 10 I need use the URL App-Prefs:root=Privacy&path=LOCATION.Rankins
@Rankins in IOS 11 URL(string: "App-prefs:root=LOCATION_SERVICES") still works without problems...Variorum
As of May 25, 2018 our app got rejected because of using prefs:root under Guideline 2.5.1 - Performance - Software RequirementsCarminacarminative
S
6

🚨🚨

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

Shugart answered 15/3, 2019 at 18:37 Comment(0)
R
4

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)
}
Richards answered 12/2, 2020 at 5:8 Comment(3)
please share the error message why its reject my app is still live with this codeRichards
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 StoreSailesh
#50041058Richards
E
3

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://mcmap.net/q/117755/-opening-the-settings-app-from-another-app

Encase answered 6/6, 2016 at 10:8 Comment(5)
@Joe Susnick Do you have a solution for iOS 10? Thanks for any helpMesh
@EricBrunner yes, I posted above but the url: App-Prefs:root=Privacy&path=LOCATION worked for me.Premium
@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!Mesh
@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.Premium
As of May 25, 2018 our app got rejected for using prefs:root under Guideline 2.5.1 - Performance - Software RequirementsCarminacarminative
B
3

Step 1: Click on project name >> target>> info >> url Types

enter image description here

Step 2:

-(IBAction)openSettingViewToEnableLocationService:(id)sender
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
}
Boanerges answered 6/6, 2016 at 10:8 Comment(2)
Apple prohibits the use of this API now, you might not want to use it anymore since it may lead to rejection by app review: #49060168Executrix
App Rejected by Apple.Qintar
M
3

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.

Megalith answered 10/5, 2019 at 21:31 Comment(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?Kaolack
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 :(Marcum
D
1

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)
}
Deming answered 15/2, 2023 at 12:8 Comment(1)
App got rejected or not by using above optionAbutting
S
0

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)
}
Succinylsulfathiazole answered 26/1, 2018 at 14:39 Comment(1)
you 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)Variorum
C
0

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()
Cipolin answered 22/2, 2023 at 9:25 Comment(5)
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.Pyotr
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.Cipolin
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.Pyotr
I see. You have a point. Do you think it's nonetheless useful to leave this answer here? Otherwise I maybe should delete it.Cipolin
The answer is useful. It just needed the extra little detail about not always showing the question to the user.Pyotr
I
-1

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)
}
Inebriety answered 22/1, 2018 at 15:59 Comment(2)
As of May 25, 2018 our app got rejected because of this under Guideline 2.5.1 - Performance - Software RequirementsCarminacarminative
@Carminacarminative even our app got rejected due to this. Do you know alternative to this? or workaround to get this working ? help would be appreciatedAinsley

© 2022 - 2024 — McMap. All rights reserved.