Mac Catalyst: multi-window without supporting multi-window in iPad app?
Asked Answered
T

1

5

I'm writing a card game app for iPad and want to bring it to the Mac using Catalyst. The game is not one where supporting multiple windows makes a lot of sense. However, there is a statistics screen that I show in a modal form sheet on iPad, which I would rather open in a new window on Catalyst. That's the only scenario where I would want to add a new window.

Is there a way for me to support multi-window apps, but only on the Catalyst version of the app? If I check the "Supports multiple windows" checkbox in the app target settings in Xcode, then the user is suddenly granted the option to open more windows on the iPad app from App Expose, which isn't the functionality I'm looking for.

enter image description here

Tenuis answered 4/4, 2020 at 18:38 Comment(2)
Did you ever figure out a solution to this?Mercie
I didn’t, sadly. Ended up sticking to single window using modals on Mac, even though it’s a worse experience. Maybe Catalyst 2.0 will be better.Tenuis
M
6

You can do this by adding a second UIApplicationSceneManifest to your Info.plist, with -macos added to it, with different settings than for the iOS/iPadOS target. For example:

<key>UIApplicationSceneManifest</key>
<dict>
    <key>UIApplicationSupportsMultipleScenes</key>
    <false/>
    <key>UISceneConfigurations</key>
    <dict>
        <key>UIWindowSceneSessionRoleApplication</key>
        <array>
            <dict>
                <key>UISceneConfigurationName</key>
                <string>Default Configuration</string>
                <key>UISceneDelegateClassName</key>
                <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
            </dict>
        </array>
    </dict>
</dict>
<key>UIApplicationSceneManifest-macos</key>
<dict>
    <key>UIApplicationSupportsMultipleScenes</key>
    <true/>
    <key>UISceneConfigurations</key>
    <dict>
        <key>UIWindowSceneSessionRoleApplication</key>
        <array>
            <dict>
                <key>UISceneConfigurationName</key>
                <string>Default Configuration</string>
                <key>UISceneDelegateClassName</key>
                <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
            </dict>
        </array>
    </dict>
</dict>

This plist will allow support for multiple scenes on macOS, but not iPadOS.

Additionally, you can prevent new windows from being created through the file menu by removing the new scene button. Add this code to your App Delegate.

- (void)buildMenuWithBuilder:(id<UIMenuBuilder>)builder {
    [builder removeMenuForIdentifier:UIMenuNewScene];
}

Using platform-specific keys is not documented anywhere, but @stroughtonsmith has made developers aware that it works.

Mercie answered 15/6, 2020 at 22:41 Comment(3)
Oh interesting, I didn’t know you could add a platform specific manifest. Nice find! How’d you find this? I’m reasonably sure that’s not documented anywhere 😁Tenuis
A friend told me, not sure how he found it. But yeah, works perfectly.Mercie
fwiw UIApplicationSceneManifest-macos isn't working for me on Big Sure/Xcode 12. The New menu item shows up, but it doesn't do anything. Setting true in the non-macos version of the manifest makes the New menu item do the right thing, but unfortunately works on iPad too.Reilly

© 2022 - 2024 — McMap. All rights reserved.