I've found a workaround which can prevent this crash from happening.
if #available(iOS 16.0, *) {
let keyWindow = UIApplication.shared.connectedScenes
.filter { $0.activationState == .foregroundActive }
.first(where: { $0 is UIWindowScene })
.flatMap { $0 as? UIWindowScene }?.windows
.first(where: \.isKeyWindow)
if let window = keyWindow {
window.rootViewController?.presentedViewController?.dismiss(animated: true)
}
}
Using UIKit to dismiss the model seem to work fine and won't trigger the crash. But this is not ideal and I don't know when this can get fixed.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: