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

标签 ios swift settings

我有一个 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/

相关文章:

android - 如何检查特定应用程序是否具有管理员权限,并转到其管理屏幕?

ios - 单元格中的标签高度不会动态改变高度

ios - 如何在 swift 中找到 QuadCurve 和 Line UIBezierPaths 之间的交点(CGPoint)?

ios - 每天和每半小时重复一次 UNNotifications

ios - 如何集成 InAppSettingsKit?

java - 显示另一个 Activity 而不是 MainActivity

ios - Swift 核心数据关系和播种数据

ios - 将快速闭包传递给以 block 作为参数的 Objective-C 函数

ios - 确保单例属性无法通过其他实例访问

ios - Codable 句柄单个或数组