我希望在 macOS 上不显示 SwiftUI 应用程序的窗口。该应用程序使用 SwiftUI 的应用程序生命周期,并且仅在状态栏中运行。启动时显示一个窗口是不必要的。然而,我不确定如何避开 WindowGroup
。没有 EmptyScene
,在 WindowGroup
中放置 EmptyView
当然会创建一个空白窗口。
@main
struct MyApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
我基本上只需要应用程序委托。我猜使用默认的AppKit生命周期更有意义,但如果有一种方法可以使用SwiftUI的生命周期,那就太好了。