The “prefs” URL Scheme is not working in iOS 10 (Beta 1 & 2)

眉间皱痕 提交于 2019-11-27 04:32:57

Just replace prefs to App-Prefs for iOS 10

Below code works for iOS 8,9,10

Swift 3.0 and Xcode >= 8.1

if #available(iOS 10.0, *)
{
       UIApplication.shared.openURL(URL(string: "App-Prefs:root=SOMETHING")!)
}
else
{
       UIApplication.shared.openURL(URL(string: "prefs:root=SOMETHING")!)
}

Swift 2.2

if #available(iOS 10.0, *)
{
      UIApplication.sharedApplication().openURL(NSURL(string:"App-Prefs:root=SOMETHING")!)
}
else
{        
    UIApplication.sharedApplication().openURL(NSURL(string:"prefs:root=SOMETHING")!)
}

Works for me.

Happy Coding 😊

You can use UIApplicationOpenSettingsURLString to open your own app's settings (this has been available since iOS 8) but any other prefs: URL is now considered a private API and use will result in app rejection.

You can use Prefs:root=SOMETHING

iOS 10 updated URL Scheme for Settings, you need to upcase the "p".

Ref: https://github.com/cyanzhong/app-tutorials/blob/master/schemes.md

NOTICE: It only works on Widgets, not works in Apps. (iOS 10.0.2)

@Saumil Shah's solution works in App, is more useful.

For the record, for Location services App-Prefs:root=Privacy&path=LOCATION worked for me. When I tested on a device and not a simulator.

I won't list the things I tried that did not work, it's a long list.

Usage example that assumes either location services are disabled or permission is denied or not determined:

if !CLLocationManager.locationServicesEnabled() {
    if let url = URL(string: "App-Prefs:root=Privacy&path=LOCATION") {
        // If general location settings are disabled then open general location settings
        UIApplication.shared.openURL(url)
    }
} else {
    if let url = URL(string: UIApplicationOpenSettingsURLString) {
        // If general location settings are enabled then open location settings for the app
        UIApplication.shared.openURL(url)
    }
}

If anyone is interested in a "gray area" API, you can use:

//url = "prefs:root=SOMETHING"
[[LSApplicationWorkspace defaultWorkspace] openSensitiveURL:url withOptions:nil];

This will give you what you want. Hide it well, and it works in iOS 10.

chawki

This is not available on iOS 11, we can just open Settings like:

if let url = URL(string:UIApplicationOpenSettingsURLString) {
   if UIApplication.shared.canOpenURL(url) {
     UIApplication.shared.open(url, options: [:], completionHandler: nil)
   }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!