How to exit an app developed on VisionPro using code?

I developed an app on VisionPro and created a button that allows users to exit the app instead of being forced to exit. I use the ”exit (0)“ scheme to exit the application, but when I re-enter, the loaded window is not the initial window, so is there any relevant code that can be used? Thank you

Hello @iOS-LI, thank you for your question!

When the last window of a visionOS application is closed by the person using the app, rather than exit the app entirely, the operating system places the app in the background until the person opens the app again. It is not recommended to force your application to terminate from code as you are describing.

The lifecycle of your app is managed in part by the operating system. Great visionOS apps work well regardless if they are resumed or launched for the first time, so you should design your apps with all this in mind.

To listen for changes in your scene's lifecycle, you can observe changes to a ScenePhase value in your app or view's Environment. When your scene leaves the background and becomes active you could present the person using your app the option of resuming or returning to your start screen, for example.

Let me know if you have any more questions!

How to exit an app developed on VisionPro using code?
 
 
Q