12

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?

Vincent
  • 486
  • 6
  • 20

3 Answers3

10

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)
                }
            }
Vincent
  • 486
  • 6
  • 20
6

Just an update because UIApplicationOpenSettingsURLString changed.

 guard let url = URL(string: UIApplication.openSettingsURLString) else {
    return
 }
 if UIApplication.shared.canOpenURL(url) {
    UIApplication.shared.open(url, options: [:])
 }
Joule87
  • 532
  • 4
  • 13
1

You can open your app settings screen using it's bundle id, for example for CAMERA permission, you can use

if let bundleId = /* your app's bundle identifier */
    let url = URL(string: "\(UIApplication.openSettingsURLString)&path=CAMERA/\(bundleId)"),
    UIApplication.shared.canOpenURL(url) {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
    }
}

Reference: https://stackoverflow.com/a/61383270/4439983

Noor
  • 967
  • 7
  • 18