I am experiencing an issue when deep linking into a certain SwiftUI view from a link. the openTakeVC
is what is called when deep linked. Currently it was to be embedded in a UINavigationController in order to work, if I try just presenting the UIHostingController I get a crash with this error:
Thread 1: "Application tried to present modally a view controller <_TtGC7SwiftUI19UIHostingControllerV8uSTADIUM8TakeView_: 0x14680a000> that has a parent view controller <UINavigationController: 0x1461af000>."
The dismiss functionality works perfectly fine if not embedded in a UINavigationController but I am only able to deep link that view using a UINavigationController.
Is there a fix for this error or a way to dismiss a UIHostingController embedded in a UINavigationController?
func openTakeVC(take: TakeOBJ) {
DispatchQueue.main.async {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
if let _ = appDelegate.window?.rootViewController as? BannedViewController { return }
//let vc = TakeSingleViewController(nibName: "TakeSingleView", bundle: nil, take: take)
let vc = UIHostingController(rootView: TakeView(take: take))
let nav = UINavigationController(rootViewController: vc)
nav.modalPresentationStyle = .fullScreen
nav.setNavigationBarHidden(true, animated: false)
appDelegate.window?.rootViewController?.present(vc, animated: true, completion: nil)
UserDefaults.removeURLToContinue()
}
}
in TakeView
@Environment(\.presentationMode) var presentationMode
Button {
UIImpactFeedbackGenerator(style: .light).impactOccurred()
presentationMode.wrappedValue.dismiss()
} label: {
Image(systemName: "xmark")
}
}