在 Mac 上如何确定是否发生用户注销
我对 Mac 平台和 Objective-C 非常陌生,在我的应用程序中,我想知道如何确定用户正在注销并在此之前执行一些操作。有这方面的信息或指示吗?
I am very new to the Mac platform and Objective-C in general and in my application I would like to know how to determine that a user is logging out and perform some actions prior to this. Any info or pointers for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些 Apple 文档 自定义登录和注销 和 技术说明 2228。但恐怕不再直接支持注销挂钩。
因此,第二种最佳方法是运行无头 Cocoa 应用程序,并使用
NSWorkspace
从系统接收通知,请参阅 文档 和 列表可用通知。要制作无头 Cocoa 应用程序,您需要在其
Info.plist
中设置一个名为LSUIElement
的条目,请参阅 此处。通过将LSUIElement
设置为yes,应用程序不会出现在dock中,而是在后台执行各种操作。The official way to put the hook at logging in / logging out is described in these Apple documents Customizing Login and Logout and Tech Note 2228. But I'm afraid that the log-out hook was no longer directly supported.
So, the second best way is to run a headless Cocoa app, and receive a notification from the system using
NSWorkspace
, see the document and the list of available notifications.To make a headless Cocoa app, you need to set an entry in its
Info.plist
calledLSUIElement
, see here. By settingLSUIElement
to be yes, the app don't appear in the dock, but perform various operation in the background.查看此工作区服务文档中的接收工作区通知。
Take a look at Receiving Workspace Notifications in this Workspace Services document.