Cocoa - 防止系统关闭

发布于 2024-10-29 05:18:54 字数 365 浏览 0 评论 0原文

嘿伙计们, 我还有一个问题,在网上找不到答案。我希望你能帮助我。

我正在编写一个 Cocoa 应用程序,它在后台运行并为我执行多项任务。如果我退出应用程序,我会显示 NSAlert。这一切都很好。但我的问题来了。此警报是从 applicationShouldTerminate: 方法内部呈现的。因此,如果我注销,则会触发此方法并显示警报。但即使我返回 NSTerminateCancel,OSX 也会退出应用程序并注销,而不等待响应。

我如何强制操作系统停止从我的应用程序中注销/关闭,以便用户(我自己:-D)可以决定要做什么。 (这只是一个对话框,询问是否保存已完成的工作。)

我希望你能帮助我......

Sandro

Hey Guys,
I've another question I couldn't find an answer on the internet. I hope you can help me.

I'm writing an Cocoa Application which runs in background and does several tasks for me. If I quit the application, I show a NSAlert. That all works great. But here comes my problem. This Alert is presented from inside the applicationShouldTerminate: Method. So if I Logout, this method is triggered and the alert is shown. But OSX quits the application and logs out without waiting for a response even if I return NSTerminateCancel.

How can I force the OS to stop logging out/shutting down from within my application, so that the user (myself :-D) can decide what to do. (It just a dialog which asks if the done work shall be saved or not.)

I hope you can help me...

Sandro

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

待"谢繁草 2024-11-05 05:18:54

Mac OS X 基于 UNIX。当系统关闭时,会发送 SIGKILL 信号来终止所有进程。但在此之前,会发送 SIGTERM 信号,通知进程即将关闭。

我认为解决方案在于处理信号,即检测和阻止它们。关于这一点,您可以在 GNU 中找到指导C 库:信号处理:阻塞信号。

那里的示例可能是关于 BSD 的,但您可能知道 OS X 核心是从 BSD 派生的,因此 OS X 支持它。此外,Objective-C 也支持 C。

Mac OS X is based on UNIX. When a system shuts down, the SIGKILL signal is send that terminates all the processes. But before that, the SIGTERM signal is sent that informs the processes that a shutdown is going to take place.

I think the solution lies in handling of the signals, i.e. detecting and blocking them. Regarding this, you may find guidance in GNU C Library: Signal Handling: Blocking Signals.

The examples there maybe about BSD, but you may know that the OS X core is derived from BSD and therefore OS X supports it. Moreover, C is supported in Objective-C.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文