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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With