5

Is there a way to check if the phone is locked? Or do I receive a notification of the phone is going to be locked?

My app runs in the background, continues to play audio, so applicationWillResignActive: isn't really what I am looking for.

TurqMage
  • 3,321
  • 2
  • 31
  • 52

2 Answers2

5

Checkout UIApplicationProtectedDataWillBecomeUnavailable. This appears to be called when the device is locked. iOS4 + only.

UIApplicationProtectedDataWillBecomeUnavailable

http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html

logancautrell
  • 8,762
  • 3
  • 39
  • 50
  • this is interesting, but I think the poster mean the "lock screen" – yano Jun 29 '12 at 23:40
  • For completeness UIApplication also posts the `UIApplicationProtectedDataDidBecomeAvailable` notification and has the `protectedDataAvailable` property for determining the current state. – ospr Jul 22 '15 at 15:49
  • But protected data is only unavailable if the device is locked AND data protection is enabled. But what about if data protection is not enabled? – user102008 Oct 21 '16 at 03:44
3

You can't, directly. Indirectly, you can watch for accelerometer on/off notifications.

Why do you want to detect this event in the first place?

Community
  • 1
  • 1
Shaggy Frog
  • 27,575
  • 16
  • 91
  • 128
  • When the phone is locked the way AudioUnits handle the Audio playback is different, they expect more data per callback. I would like my buffer scheme to be aware of this. - I knew this question had to be asked before I couldn't find it! – TurqMage Nov 01 '11 at 16:19
  • 1
    @TurqMage : Then why not just monitor the audio callback buffer size directly? (It might change for other reasons than your app being put in the background.) – hotpaw2 Nov 01 '11 at 20:57