Mac Catalyst scene auto recreation

Hi, I have Mac catalyst app, that usually shows one window, but under some circumstances I open another one with different content (so it is multi-windowed app, but not in a way of opening several documents in instances of the same type of window). I did manage to setup SceneDelegate, open scenes etc., but I have still some problems.

  1. After app launch, old scenes are automatically recreated. Is there a way to stop it? I want to always start with main scene, and only open the second one from code.
  2. Is there a way to set size and position of a window before it is shown? I can do it by acquiring NSWindow from UIWindow and then using AppKit from another bundle. But this can only be done after the window appears on screen. As a result, user sees window "jump".
  3. When scene is being created (or maybe just recreated to restore previous session), window gets the same position it had before. Is there any way to control it? How this mechanism exactly works? Where are the previous positions stored and can they be modified? How a newly created scene gets its size and position?

Replies

"System Preferences -> General -> Close windows when quitting an app" controls whether a multi-window Catalyst app restores the size, position, and contents of all windows from the previous session. This uses the same mechanism that is also used for AppKit apps. You can use requestSceneSessionDestruction:options:errorHandler: to close windows in code, even from scene:willConnectToSession:options:, when the scene is being restored. I believe newly created scenes are centered on screen by default, but you can influence their initial size by temporarily setting the UISceneSizeRestrictions.

Thanks. Does it mean that if I create a new scene by myself through requestSceneSessionActivation(), I will never be able to open window on the position I want, no matter what I do? The only way is to first let window show at default location, and then acquire NSWindow and move it by appkit means? SIze restrictions work for size, I appreciate that, but position is also important for me.

There is now Catalyst-specific API that allows you to resize and position your windows!

For more details, check out the talk "Bring your iOS app to the Mac" from WWDC 2022.

Re-opening this since I am experiencing a similar situation to the original post.

When calling requestSceneSessionDestruction:options:errorHandler:, all my windows close, effectively quitting my Catalyst app. Is there any way to only close one window?

Post not yet marked as solved Up vote reply of Dr7 Down vote reply of Dr7