In a SwiftUI VisionOS app that opens with one .plain window and another .volumetric window, I want to automatically close the Volume when the user closes the plain window. Attempting to do so with
ContentView().onDisappear{ dismissWindow(id: kVolumeId) }
results in
Page tried to end immersive session initiated by a different page
I have not found that error documented anywhere. Any advice?
Hi @avitzur ,
You can use ScenePhase to check if you've closed ContentView and dismiss the volumetric window there.
For example:
@Environment(\.scenePhase) var scenePhase
...
WindowGroup {
ContentView()
}
.onChange(of: scenePhase) { _, new in
switch new {
case .background: dismissWindow(id: "volumetricWindow")
case .active: print("active")
case .inactive: print("inactive")
@unknown default:
print("default")
}
}