iPadOS 15, cannot replace/destroy foreground scene, and activate an existing background scene.

I have a document based app, and if the user tries to open a document in the active/foreground scene, and that document is already open in another existing scene, I would like to activate that existing scene, and destroy the current foreground one.

I do it like that:

UIApplication.shared.requestSceneSessionActivation(existingSession, userActivity: activity, options: nil) UIApplication.shared.requestSceneSessionDestruction(foregroundSession, options: nil)

When I run this code, the foreground scene is destroyed, but the activated one is not brought to foreground, it simply takes me to home screen.

On iOS14, it kinda works, the existing one is brought to foreground and splits the screen with the current foreground one for a split second, then the current one is destroyed, and the existing scene now takes all the screen. The intermediate split state is not visually nice but it does it's job. How can I achieve the same behaviour on iOS15?

Is there any UIKit engineer knowing how how to handle multiple scenes, or is it dark magic? The Apple iOS apps, Pages for instance, handle multiple scene in a elegant way, whereas my app, using the same Activate/Destroy API, looks bad.

Replacing current scene with another scene: Open doc A in scene A, then open another scene B, and open the same A doc. Pages simply shows the former scene, and the latter one disappears. I succeeded to make my app work on iOS 15, but it works in an unyielding manner, as I described above: The current scene B is shrinked to half screen, then the target one, A, is activated on the other half of the screen, then B scene is destroyed, and finally scene A is enlarged on the whole screen.Opening a document from Spotlight, that's already open in one of the existing scenes, does not activate that particular scene. Instead, it activates the last used scene, EVEN if there is another scene that has that doc already open. (I do set 'prefersToActivateForTargetContentIdentifierPredicate', but no luck). On Apple Pages, it activates the correct scene.
iPadOS 15, cannot replace/destroy foreground scene, and activate an existing background scene.
 
 
Q