Detect if iPhone screen is on/off

前端 未结 3 1702
醉话见心
醉话见心 2021-02-05 22:41

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)applicationWi

3条回答
  •  孤街浪徒
    2021-02-05 23:27

    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.

提交回复
热议问题