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

标签 swift uikit swiftui uialertaction

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

相关文章:

ios5 - 为什么 -[[UIButton 外观] setBackgroundImage] 会影响 UIBarItem 对象的初始外观以及如何纠正它?

iphone - UIButton 事件 'Touch Up Inside' 不起作用。 'Touch Down' 工作正常

xcode - UIBarButtonItem 选择器在 viewDidLoad() 时被调用,而不是仅触摸

swift - 在 SwiftUI 的 ForEach 中获取索引

当直接设置选择而不是从 viewModel 设置选择时,SwiftUI NavigationLink 行为会有所不同

ios - 使用 UITapGestureRecognizer 显示 UIPickerView

ios - Swift - 带有图像的 UIAlertController

ios - 如何使用 SwiftUI 在另一个 View 中创建 View ?

swift - 订购手势识别器

swift - 使用perfectLib错误 '' ld : library not found for -lCOpenSSL for architecture x86_64"