12

我无法让“prefs”URL 方案在 iOS 10(Beta 1)中工作。
它设置正确,因为同一个应用程序在 iOS 9 上运行良好。

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

代码:

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

更新: (Beta 2)
仍然无法在 Beta 2 中工作。
它似乎是一个错误。例如,如果您想在 iOS 10 中使用 GameCenter 邀请某人并且您没有登录 iMessage,您会收到一个弹出窗口,要求您登录。但是“设置”按钮绝对没有任何作用。

4

6 回答 6

19

只需替换prefsApp-PrefsiOS 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")!)
}

斯威夫特 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")!)
}

为我工作。

快乐编码

于 2017-02-16T06:49:16.133 回答
4

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

于 2016-07-26T11:01:38.207 回答
4

您可以使用Prefs:root=SOMETHING

iOS 10 更新了设置的 URL 方案,您需要将“p”大写。

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

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

@Saumil Shah 的解决方案适用于 App,更有用。

于 2016-10-07T08:03:44.683 回答
3

作为记录,位置服务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)
    }
}
于 2017-06-22T16:22:37.553 回答
1

如果有人对“灰色区域”API 感兴趣,您可以使用:

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

这会给你你想要的。隐藏它,它在 iOS 10 中工作。

于 2016-08-23T13:04:38.987 回答
1

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

if let url = URL(string:UIApplicationOpenSettingsURLString) {
   if UIApplication.shared.canOpenURL(url) {
     UIApplication.shared.open(url, options: [:], completionHandler: nil)
   }
}
于 2018-02-15T14:47:08.890 回答