简体   繁体   English

如何打开设置对话框和iOS 11的子部分

[英]How to open settings dialog and sub sections iOS 11

I have a UIAlertController with one Button named "Settings". 我有一个带有一个名为“设置”的按钮的UIAlertController。 With a tap on that i want to go to a specific section (eg Bluetooth) within the settings App. 点击后,我想进入设置应用程序内的特定部分(例如蓝牙)。 I saw many solutions here, but they all does not work for iOS 11. 我在这里看到了许多解决方案,但它们都不适用于iOS 11。

Here is my Code: 这是我的代码:

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

I also added under App->Target->Info->URLTypes->URL Schemes: "App-Prefs". 我还在App-> Target-> Info-> URLTypes-> URL方案下添加了“ App-Prefs”。 I also tried "prefs" But nothing is working. 我也尝试过“偏好”,但没有任何效果。

Does anyone have a solution for iOS 11? 有人针对iOS 11提供解决方案吗? Any help is highly appreciated 任何帮助都受到高度赞赏

You just try UIApplicationOpenSettingsURLString without App-Prefs 您只需尝试不带App-Prefs的UIApplicationOpenSettingsURLString

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM