简体   繁体   中英

Is it possible to skip launchscreen.storyboard file when running a multiplatform SwiftUI app on macOS?

I selected Multiplatform template when creating a SwiftUI app in Xcode (it's Xcode 14.0 beta, in case it matters). My purpose is to run the app on iOS. I selected Multiplatform template just because I thought it would be fun to see how it runs on macOS .

In WWDC 2020, Apple introduced an Info.plist based approach to implement launch screen for SwiftUI apps. Unfortunately that approach was broken in Xcode 13. My experiment shows it's still not working in Xcode 14.0 beta, so I work around the issue by using a storyboard file to implement launch screen.

However, since storyboard is based on UIKit , that means it doesn't work on macOS . That explains why Xcode reported the following error when I tried to run the app on macOS :

iOS storyboard doesn't support device type 'mac'

So I wonder, given the fact that the Info.plist based approach is broken in Xcode 13 and 14, how does one implement launch screen in a multiplatform app? Is it possible to skip the storyboard file on macOS ? I checked around in Xcode but didn't find a way.

An additional question: which is the common approach to write app on macOS , writing a multiplatform app as I described above or writing two separate apps, one for iOS and one for macOS ? Thanks.

Storyboards are not based on UIKit , they are based on Cocoa which is also responsible for UIKit & AppKit .

The error you're receiving is because your LaunchScreen.storyboard is specific to iOS , & not because it's base on UIKit (it's not). Also you can have storyboards when building for Mac .

To solve the problem: Open LaunchScreen.storyboard , expand the right sidebar, click on the document icon & uncheck your macOSTarget under Target Membership .

I've found that this works for a multiplatform app:

  1. Go to Build Phases -> Copy Bundle Resources
  2. Click on the dropdown for the storyboard resources
  3. Select iOS only

(Screenshot is from XCode 14 beta)

复制捆绑资源

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM