Hello guys. Today I am going to tell you how to detect if the device is locked or not from today extension or some people call it widget. Apple has not provided direct solution to this but there is a way to find if the device is locked or not.

After doing search for sometime, I found out a solution for this. The approach is not direct but this really works fine. The solution is trying to access health data from Apple. Apple don’t allow you to access health related data if your device is locked. So, by taking this idea, I was able to make device lock state. 

Here is the code.

Let me know if there is any confusion or problem. I will be happy to help.

Hope this is helpful to you.

Happy coding.