gpt4 book ai didi

swift - SwiftUI 中是否有等效的 openSettingsURLString ?

转载 作者:行者123 更新时间:2023-12-03 18:36:28 25 4
gpt4 key购买 nike

我想创建一个警报,在用户第一次拒绝使用相机后将用户重定向到设置应用程序,但到目前为止我看到的唯一方法是使用 UIKit 和

let settingsAction = UIAlertAction(title: "Settings", style: .default, handler: {action in
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)
})

在 SwiftUI 中,警报中有一个操作选项,我如何才能通过 SwiftUI 的警报版本正确打开设置?
.alert(isPresented: $alertVisible) { () -> Alert in Alert (title: Text("Camera access required to take photos"), message: Text("Go to Settings?"), 
primaryButton: .default(Text("Settings"), action: UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)),
secondaryButton: .default(Text("Cancel"))

最佳答案

这里是

.alert(isPresented: $alertVisible) {
Alert (title: Text("Camera access required to take photos"),
message: Text("Go to Settings?"),
primaryButton: .default(Text("Settings"), action: {
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
}),
secondaryButton: .default(Text("Cancel")))
}

关于swift - SwiftUI 中是否有等效的 openSettingsURLString ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62178494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com