我有一个 UIAlertController,其中有一个名为“Settings”的按钮。轻按一下我想转到设置应用程序中的特定部分(例如蓝牙)。我在这里看到了很多解决方案,但它们都不适用于 iOS 11。
这是我的代码:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidAppear(_ animated: Bool) {
let alertView = UIAlertController(title: "Info", message: "message", preferredStyle: .alert)
alertView.addAction(UIAlertAction(title: "Settings", style: .cancel, handler: { (alert) in
UIApplication.shared.open(URL(string:"App-Prefs:root=Settings&path=General")!, options: [:], completionHandler: nil)
}))
self.present(alertView, animated: true, completion: nil)
}
}
我还在 App->Target->Info->URLTypes->URL Schemes 下添加:“App-Prefs”。 我也试过“首选项” 但没有任何效果。
有人有适用于 iOS 11 的解决方案吗? 非常感谢任何帮助
最佳答案
您只需尝试不使用 App-Prefs 的 UIApplicationOpenSettingsURLString
if let url = URL(string:UIApplicationOpenSettingsURLString) {
if UIApplication.shared.canOpenURL(url) {
let url = UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
关于ios - 如何打开设置对话框和子部分 iOS 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47124521/