Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 967
Vincent Avatar asked Mar 19 '18 12:03

Vincent


3 Answers

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)
                }
            }
like image 58
Vincent Avatar answered Oct 07 '22 06:10

Vincent


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: [:])
 }
like image 29
Joule87 Avatar answered Oct 07 '22 06:10

Joule87


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

like image 1
Noor Avatar answered Oct 07 '22 07:10

Noor