On a Mac how to determine a user logout is occuring
I am very new to the Mac platform and Objective-C in g开发者_开发知识库eneral 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?
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
called LSUIElement
, see here. By setting LSUIElement
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.
NSWorkspaceWillPowerOffNotification
Posted when the user has requested a logout or that the machine be powered off.
精彩评论