[iOS] Scene disconnect closes the XAML Window, but iOS also disconnects backgrounded scenes that can reconnect
Current behavior
Found by code review; not reproduced on a device yet.
UnoUISceneDelegate.DidDisconnect → NativeWindowWrapper.OnSceneDisconnected() raises Closing/Closed and closes the XAML Window.
UIKit also disconnects scenes that are merely backgrounded, to reclaim memory, and those may reconnect later (sceneDidDisconnect(_:): "The scene may reconnect later, as its session was not necessarily discarded"). The signal that the user actually closed the window is application(_:didDiscardSceneSessions:), which UnoUIApplicationDelegate does not handle.
Resulting sequence on iPad:
- The app has a secondary window, and the user backgrounds it.
- iOS reclaims the scene →
DidDisconnect→ Uno closes the XAMLWindow(andWindow.Closedfires even though the user never closed it). - The user taps the window in the app switcher → the same session reconnects.
connectionOptionscarries no Uno GUID, so the window is either destroyed (No window is awaiting a scene) or matched through the "oldest pending window" fallback and takes an unrelated pending window.
Expected behavior
A disconnect only removes the window's native surface. The XAML Window stays alive and is re-bound when the same session (UISceneSession.PersistentIdentifier) reconnects. Window.Closed fires when the session is discarded, or when the app calls Close().
How to reproduce it (as minimally and precisely as possible)
- SamplesApp (scene manifest enabled) on the iPad simulator. Open a secondary window.
- Background the app, then force scene disconnection. Either use Xcode → Debug → Simulate Memory Warning while backgrounded, or open enough other apps. The disconnect can be confirmed with a log in
OnSceneDisconnected. - Return to the secondary window from the app switcher.
- Suspected actual: the window's
Closedwas raised, and the reconnected session is discarded or shows the wrong content.
Workaround ️
None known.
Renderer
- Skia
- Native
Affected platforms ️
iOS
Uno.Sdk version (and other relevant versions)
master (after #19082)
IDE version
N/A
Anything else we need to know?
The proposed redesign that fixes this is in the linked enhancement issue. Related: #19082, #8341.
Source: unoplatform/uno