how to detect the locked/unlocked screen status with swift

I need to detect if the screen il locked or unlocked when my app is running in background.

I can't find documentation regarding this matter for swift programming.

Some source reference ?

Replies

If you try to send a command and the device is locked, data protection will prevent you from accessing the keychain items and you’ll get a reasonable error. What do you need the notification for?

I think the reason the code was done this way is because IoT framework we're using may not be giving a descriptive error but I agree it would be the cleanest solution. Anyway I fear this little extension might be short-lived given the warnings telling us to move towards WidgetKit which sadly can't be used for this kind of widget for now ;)

Thanks for the quick & helpful answers !

Happy holidays

Bioche