I am currently tryting to detect a user logout in macOS 10.14 (Mojave). I found this, which was working in the past:
Catching Logoff (not power off) event on MAC using objective C
The code I use is:
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;
}
But the value I get is always zero (0).
Did something change in Mojave or is there another mechanism? This code is called in the applicationShouldTerminate function in my AppDelegate.