3

From what I understand, UIApplication.sharedApplication().protectedDataAvailable should return false when the phone is locked and protected data is enabled on the iPhone (apparently setting a passcode enables it).

However, despite of the scenario, it always returns true.

Once my app gets reawaken by iOS due to Corebluetooth State Preservation and Restoration, I need to immediately know whether the phone is locked.

I've implemented event listeners to know when the phone gets locked/unlocked, but they are only useful once the lock state changes, I am unable to determine the lock state prior to an event.

Any ideas? Thanks

UPDATE:

this is what I use in applicationDidFinishLaunchingWithOptions:

self.phoneLockDetection.isPhoneLocked = !UIApplication.sharedApplication().protectedDataAvailable
Lee Andrew
  • 798
  • 7
  • 28
  • You need to show some code so that people can help. As a first guess, make sure that you're waiting long enough -- there's a 10 second grace period after the screen is locked before the protected data is locked. You can see it happen by watching the phone's console log in Xcode > Window > Devices. – Ewan Mellor Nov 14 '15 at 18:56
  • I just updated the question with some info. I wasn't able to find where exactly in the logs I should look for the lock state event but I did wait a bit more before testing it and you're right, it worked as expected. Thanks a lot. Do you mind explaining a little further where this events show up in the log? In the devices list, I select my phone then View Device Logs, what then? Thanks – Lee Andrew Nov 14 '15 at 19:06

1 Answers1

0

Not under View Device Logs -- that's where you're going to see crash dumps.

There's a device console on Xcode > Window > Devices > Your Device. It might be collapsed -- click the triangle button at the bottom left of the right-hand pane if so.

I see the following in the console log:

Nov 14 12:07:30 Ewan-Mellors-iPad SpringBoard[54] <Warning>: [MPUSystemMediaControls] Disabling lock screen media controls updates for screen turning off.
Nov 14 12:07:30 Ewan-Mellors-iPad UserEventAgent[775] <Error>:  LockStateNotifier aksNotificationCallback posting notification: com.apple.mobile.keybagd.lock_status
Nov 14 12:07:30 Ewan-Mellors-iPad UserEventAgent[775] <Notice>: (Note ) PIH: Lock status changed.
Nov 14 12:07:30 Ewan-Mellors-iPad MobileMail[192] <Warning>: Key bag transitioning from unlocked to locking

And then ten seconds later:

Nov 14 12:07:40 Ewan-Mellors-iPad kernel[0] <Notice>: AppleKeyStore:Sending lock change 1 for handle 0
Nov 14 12:07:40 Ewan-Mellors-iPad UserEventAgent[775] <Error>:  LockStateNotifier aksNotificationCallback posting notification: com.apple.mobile.keybagd.lock_status
Nov 14 12:07:40 Ewan-Mellors-iPad UserEventAgent[775] <Notice>: (Note ) PIH: Lock status changed.
Nov 14 12:07:40 Ewan-Mellors-iPad MobileMail[192] <Warning>: Key bag transitioning from locking to locked
Ewan Mellor
  • 6,747
  • 1
  • 24
  • 39
  • Ewan Mellor's advice on how long I should wait before protectedDataAvailable's value is updated solved it for me. Thanks. – Lee Andrew Nov 14 '15 at 20:15