从今日扩展/小工具打开设置应用程序?

时间:2018-01-22 12:36:40

标签: ios swift today-extension

是否可以从widget / today扩展程序直接打开“设置”应用程序?

我已尝试过以下代码,但遗憾的是它无效

let url = URL(string:UIApplicationOpenSettingsURLString)!
extensionContext?.open(url) { _ in }

1 个答案:

答案 0 :(得分:1)

此代码应该正常工作


        guard let url = URL(string: UIApplicationOpenSettingsURLString) else {
            return
        }
        extensionContext?.open(url, completionHandler: { (success) in
            if !success {
                var responder = self as UIResponder?

                while (responder != nil){
                    let selectorOpenURL = NSSelectorFromString("openURL:")
                    if responder?.responds(to: selectorOpenURL) == true {
                        _ = responder?.perform(selectorOpenURL, with: url)
                    }
                    responder = responder?.next
                }
            }
        })

但我不确定"其他评论"手段 enter image description here