没有 windows 打开时 Macos 应用程序正在关闭
Macos app is getting closed when there're no windows open
我使用以下代码使其重新打开并防止在您单击关闭按钮时关闭。
问题是它只是关闭(dock 中应用程序图标下的点消失)
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return false
}
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
for window in NSApplication.shared.windows {
window.makeKeyAndOrderFront(self)
}
return true
}
更新
当我保持主 window 打开时,应用程序图标不会从 dock 中消失。
在您的 Info.plist 中将 NSSupportsAutomaticTermination 设置为否。
我使用以下代码使其重新打开并防止在您单击关闭按钮时关闭。
问题是它只是关闭(dock 中应用程序图标下的点消失)
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return false
}
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
for window in NSApplication.shared.windows {
window.makeKeyAndOrderFront(self)
}
return true
}
更新
当我保持主 window 打开时,应用程序图标不会从 dock 中消失。
在您的 Info.plist 中将 NSSupportsAutomaticTermination 设置为否。