Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 901
UberJason Avatar asked Apr 04 '20 18:04

UberJason


People also ask

Can IOS app have multiple windows?

It is not a problem at all to add another UIWindow. Just create one and makeKeyAndVisible. Done. Remove it by making another window visible, then release the one you don't need anymore.

What is catalyst for Mac?

With Mac Catalyst, you can make a Mac version of your iPad app. Click the Mac checkbox in your iPad app's project settings to configure the project to build both Mac and iPad versions of your app. The two apps share the same project and source code, making it easy to change your code in one place.


1 Answers

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.

like image 140
Benr783 Avatar answered Oct 07 '22 04:10

Benr783