我想创建一个警报,在用户第一次拒绝使用相机后将用户重定向到设置应用程序,但到目前为止我看到的唯一方法是使用 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/