1

I'm trying to detect screen lock in iphone with swift code UIScreen.main.brightness value to get current brightness of screen. I am using it inside applicationDidEnterBackground method.

At lock screen (by pushing lock button), brightness value is 0.0 and at pushing app to background (by pushing home button) the value of brightness is greater than zero.

95% of the times results are good however there occurs some instances when brightness value on lock screen is greater than zero. Maybe because inside applicationDidEnterBackground the value of brightness is calculated before screen is actually locked in rare occasions. Does anyone know how to handle this situation gracefully?

Mumtaz Hussain
  • 925
  • 9
  • 23
  • followed this: https://stackoverflow.com/questions/44071009/can-we-detect-whether-a-user-left-through-the-home-button-or-lock-button-without But it only allows me to run the else block only no matter if I press home button or lock button. – Mumtaz Hussain Feb 21 '19 at 18:25

0 Answers0