osx - Catching Logoff (not power off) event on MAC using objective C -
can tell me how can catch user logoff event? able catch poweroff event using nsworkspacewillpoweroffnotification notification. not showing difference in logoff , power off events. want catch log off , power off separately. able catch same on windows.
first, have make sure app not participating in sudden termination. if is, can killed @ logout without opportunity react.
now, when user logs out, app kaequitapplication
('quit'
) apple event. have same effect invocation of -[nsapplication terminate:]
. can implement application delegate method -applicationshouldterminate:
notified of request quit , control app's response it.
in delegate method, can use code examine quit event , learn reason quit request:
nsappleeventmanager* m = [nsappleeventmanager sharedappleeventmanager]; nsappleeventdescriptor* desc = [m currentappleevent]; switch ([[desc attributedescriptorforkeyword:kaequitreason] int32value]) { case kaelogout: case kaereallylogout: // log out break; case kaeshowrestartdialog: case kaerestart: // system restart break; case kaeshowshutdowndialog: case kaeshutdown: // system shutdown break; default: // ordinary quit break; }
Comments
Post a Comment