AppDelegate 中未调用 applicationShouldTerminate 且未发送 NSApplicationWillTerminateNotification

applicationShouldTerminate not called in AppDelegate and NSApplicationWillTerminateNotification not being sent

我在最新的 Catalina 上使用 XCode 11.1,正在调用我的应用程序的 none 退出事件。 AppDelegate 中的 applicationShouldTerminate 如果我从任何地方观察它,我也不会得到 NSApplicationWillTerminateNotification。这是来自使用默认故事板的 XCode 应用程序模板的默认退出行为(使用菜单退出命令、Command-Q,或关闭 window with applicationShouldTerminateAfterLastWindowClosed 返回 YES)。

这发生在一个全新的 Xcode 项目模板上(如果我启动一个新的 macOS "App" 模板,然后将 applicationShouldTerminate 方法添加到应用委托中)。

正在调用其他委托方法,例如 applicationShouldTerminateAfterLastWindowClosed。

我是不是做错了什么,还是 Catalina 出了什么问题?

好吧,我想通了,这是因为 NSSupportsSuddenTermination 现在似乎默认打开了。

要禁用突然终止,请在应用的信息 属性 列表文件 Info.plist 中将此布尔值 属性 设置为 NO

NSSupportsSuddenTermination 在 Xcode 中也称为 'Application can be killed immediately when user is shutting down or logging out',并且似乎默认启用。

转到您项目的 Info.plist 并找到“当用户关闭或注销时可以立即终止应用程序”键。将其值更改为“否”