"prefs" URL 方案在 iOS 10(Beta 1 和 2)中不起作用

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

我无法让 "prefs" URL 方案在 iOS 10(Beta 1)中工作。
它设置正确,因为同一个应用程序在 iOS 9.

上运行良好

这是一个错误还是被重命名/删除了?

代码:

let settingsUrl = NSURL(string: "prefs:root=SOMETHING")
if let url = settingsUrl {
    UIApplication.sharedApplication().openURL(url)
}

更新: (测试版 2)
仍然无法在 Beta 2 中工作。
它似乎是一个错误。例如,如果你想在 iOS 10 中邀请某人使用 GameCenter,而你没有登录 iMessage,你会看到一个弹出窗口要求你登录。但是 "Settings" 按钮绝对没有任何作用。

您可以使用 UIApplicationOpenSettingsURLString 打开 您自己的 应用程序的设置(自 iOS 8 起可用)但任何其他 prefs: URL 现在被认为是私有的 API,使用会导致应用被拒绝。

如果有人对 "gray area" API 感兴趣,您可以使用:

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

这会给你想要的。 隐藏得好,在iOS10.

中有效

您可以使用Prefs:root=SOMETHING

iOS 10 更新了URL 设置方案,需要将"p".

大写

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

注意:它只适用于小部件,不适用于应用程序。 (iOS 10.0.2)

@Saumil Shah 的解决方案在 App 中有效,更有用。

只需将 prefs 替换为 App-Prefs 即可 iOS 10

下面的代码适用于 iOS 8,9,10

Swift 3.0 和 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")!)
}

适合我。

快乐编码

郑重声明,位置服务 App-Prefs:root=Privacy&path=LOCATION 对我有用。当我在设备而不是模拟器上测试时。

我不会列出我尝试过但没有用的东西,这是一个很长的清单。

假设位置服务被禁用或权限被拒绝或未确定的使用示例:

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)
    }
}

这在 iOS 11 上不可用,我们可以打开设置,例如:

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