skip to Main Content

I need to ask user to enable Location Services if disabled. I have created an Alert which asks user if he wants to enable Location. I user clicks Ok I want to open Location Services page on iPhone as seen below:

enter image description here

I am trying ‘openSettingsURLString’ but it opens App settings instead of Location Services page, this is the code:

            let url = URL(string: UIApplication.openSettingsURLString)

            let settingsAction = UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default) {
                (UIAlertAction) in UIApplication.shared.open(url!, options: [:], completionHandler: nil)
                self.dismiss(animated: true, completion: nil)
            }

            alertController.addAction(cancelAction)
            alertController.addAction(settingsAction)
            self.present(alertController, animated: true, completion: nil)

2

Answers


  1. I believe this is not possible, you can only navigate to the settings of the app itself; Apple expects the user themself to navigate to location services. . I would recommend giving the user instructions on how to navigate to location services as an alternative such as some screenshots and the path they should take.

    Login or Signup to reply.
  2. ⚠️ Caution

    There is a way to achieve the following. However, as of iOS 12, Apple
    has begun rejecting apps that use App-Prefs or prefs:root as both methods are based on undocumented APIs.

    Open Settings AppThis one should be OK to use.

    UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)
    

    Open Location Services

    If this app is for personal use only and you do not plan to submit it to the App Store, then you should be ok to use the following. Otherwise, if you do plan to release your app, Apple will reject it upon review.

    UIApplication.shared.open(URL(string: "App-prefs:LOCATION_SERVICES")!)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search