NSViewController not retaining modal presentation state across application lifecycle on macOS 13.6
I'm having a hard time understanding I'm having trouble with I'm working with an scenario where my `NSViewController` modally presents another view controller, but upon relaunching the application, the modal state is not retained. I've tried implementing the `viewWillDisappear` and `viewDidDisappear` methods in my modal view controller to manage the state, but it doesn't seem to continue after the app is closed and reopened. My modal is presented like this: ```swift let modalViewController = ModalViewController() modalViewController.modalPresentationStyle = .fullScreen self.present(modalViewController, animated: true, completion: nil) ``` I also save the current state in `UserDefaults` upon dismissing the modal, but it seems that during the launch, the code responsible for restoring this state doesn't trigger as expected: ```swift if let wasModalPresented = UserDefaults.standard.value(forKey: "wasModalPresented") as? Bool, wasModalPresented { self.present(modalViewController, animated: false, completion: nil) } ``` I've confirmed that the value in `UserDefaults` is correctly set before the app closes. However, when the app restarts, the modal view controller just doesn't appear. I've checked that the `viewDidLoad` method is called, but the modal doesn't come up. Is there a best practice for handling modal presentations that need to continue state across application sessions? Any insights or suggestions on what I might be missing would be greatly appreciated! Any examples would be super helpful. What's the correct way to implement this?