繁体   English   中英

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

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

我有一个带有一个名为“设置”的按钮的UIAlertController。 点击后,我想进入设置应用程序内的特定部分(例如蓝牙)。 我在这里看到了许多解决方案,但它们都不适用于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方案下添加了“ 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)
    }
}

暂无
暂无

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

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