I have faced a problem when my app receives NSWorkspaceWillSleepNotification but machine does not go into sleep mode. I have rewritten my code to IORegisterForSystemPower but still receive kIOMessageSystemWillSleep in the same situation.
It looks like some other app preventing the system from sleep but system still inform other apps that sleep will happen. Looks like some kind of OS design flaw or I do not get something.
Maybe there are some other reliable way to detect the sleep mode?
(This is all about idle sleep not forced sleep.)
Tested on Mac OS 10.15.7