Search code examples
swiftios11url-scheme

How to open your app's settings (inside the Settings app) with Swift (iOS 11)?


I would like to open my app's settings page inside the Settings app with Swift 4 in iOS 11. Just like the picture shows:

enter image description here

The following codes doesn't work, it will only open the Settings app:

   if let url = URL(string:UIApplicationOpenSettingsURLString) {
        if UIApplication.shared.canOpenURL(url) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
    }

The app shows in the above picture is able to do this. So I wonder if there is any way to custom the URL Scheme to make it happen?


Solution

  • Oops, it seems it works in iOS 11.4.1:

     if let url = URL(string:UIApplicationOpenSettingsURLString) {
                    if UIApplication.shared.canOpenURL(url) {
                        UIApplication.shared.open(url, options: [:], completionHandler: nil)
                    }
                }