Is there any way to detect if an iPhone's screen is on or off? For example, when the phone's screen lock button is pressed.
I've been using (void)applicationWillResignActive:(UIApplication *)application;
to prepare for such events (which works fine for the most part), but this method is also fired for incoming calls, texts, etc.
As far as I can tell, there is no documented method to determine this.
I've been playing with some workarounds, like checking if screen resolution changed, checking if the orientation is unknown, or getting the brightness of the device. Nothing has panned out yet.
Does anyone have any creative/workaround solutions for this?
If your iPhone is showing a black screen that never goes away, you should try resetting it. Black screens might appear if your iPhone overheats, encounters a major error, or the screen itself breaks. You should also plug your iPhone into a charger to make sure that it isn't simply out of battery.
Go to Settings > Accessibility. Select Motion, then turn on Reduce Motion.
Yes, there is no definitive method. UIApplication
has a property protectedDataAvailable
which will return YES
when screen is unlocked and NO
if locked only when user enables content protection. So this is the closest but unreliable I can think of. In such case, you can even listen to UIApplicationProtectedDataDidBecomeAvailable
and UIApplicationProtectedDataWillBecomeUnavailable
notifications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With