In IOS, when the device is kept idle for some time, the screen turns off and the device enters sleep mode. It also enters sleep mode when we press the power button to turn the screen off.
In my application, I wanted to detect If the device has entered/exited the sleep mode. I have followed the below links but some of these ways like observing 'Darwin notifications' is no longer allowed by apple. Other ways consider the device being locked as sleep mode, which is not precisely correct.
Is there a way to correctly determine this? Please share the apple documentation links if this is possible.
https://stackoverflow.com/questions/14191980/detect-screen-on-off-from-ios-service/14208787#14208787
https://nemecek.be/blog/104/checking-if-device-is-locked-or-sleeping-in-ios