簡體   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