How to open Location services screen from setting screen?

51,699

Solution 1

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"]];
}

Solution 2

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)
}

Solution 3

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.

Solution 4

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

Share:
51,699
Monika Patel
Author by

Monika Patel

iOS Developer

Updated on July 09, 2022

Comments

  • Monika Patel
    Monika Patel almost 2 years

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

    enter image description here

  • Erich Brunner
    Erich Brunner about 7 years
    @Joe Susnick Do you have a solution for iOS 10? Thanks for any help
  • Joe Susnick
    Joe Susnick about 7 years
    @EricBrunner yes, I posted above but the url: App-Prefs:root=Privacy&path=LOCATION worked for me.
  • Erich Brunner
    Erich Brunner about 7 years
    @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!
  • Joe Susnick
    Joe Susnick almost 7 years
    @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.
  • Ramis
    Ramis almost 7 years
    After implementing it will it pass App Store review guidelines?
  • MMSousa
    MMSousa almost 7 years
    in iOS 10 I need use the URL App-Prefs:root=Privacy&path=LOCATION.
  • Tà Truhoada
    Tà Truhoada over 6 years
    Easier: UIApplication.shared.openURL(URL.init(string: UIApplicationOpenSettingsURLString)!)
  • user25
    user25 over 6 years
    @MMSousa in IOS 11 URL(string: "App-prefs:root=LOCATION_SERVICES") still works without problems...
  • user25
    user25 over 6 years
    @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
  • MartijndeM
    MartijndeM about 6 years
    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: stackoverflow.com/questions/49059668/…
  • Ted
    Ted about 6 years
    As of May 25, 2018 our app got rejected because of using prefs:root under Guideline 2.5.1 - Performance - Software Requirements
  • Ted
    Ted about 6 years
    As of May 25, 2018 our app got rejected because of using prefs:root under Guideline 2.5.1 - Performance - Software Requirements
  • Ted
    Ted about 6 years
    As of May 25, 2018 our app got rejected for using prefs:root under Guideline 2.5.1 - Performance - Software Requirements
  • F.O.O
    F.O.O about 3 years
    question asks about going to the location services page not the app settings page
  • RsD
    RsD about 2 years
    App Rejected by Apple.