visionOS is very new at this point and working with that in SwiftUI might be difficult due to the less resources on the internet.
Today I found a warning like: Unable to present another Immersive Space when one is already requested or connected
in SwiftUI.
In this post, I will tell you why this happens and how to prevent it.
First, it’s important to note that a visionOS app can only display one space at a time. If you attempt to open a new space while the previous one is still visible, you will encounter an error. To close an open space, you can use the following code. There’s no need to specify an ID when dismissing your immersive space because only one space can be open at any given time.
import SwiftUI struct DismissImmersiveness: View { @Environment(\.dismissImmersiveSpace) var dismissImmersiveSpace var body: some View { Button("Close Immersive Space") { Task { await dismissImmersiveSpace() } } } }
Additionally, the “Unable to present another Immersive Space when one is already requested or connected” error occurs when you attempt to call the Immersive Space simultaneously from both the ContentView and the App files.
If your problem is something else, you can let us know in comment or do contact us.
If I try to dismiss an Immersive Space when one isn’t open I get an error/warning “Unable to dismiss an Immersive Space since none is opened”. Is it possible to determine with a (system) variable if an Immersive space is open?