0

I would like to know if there is any way (should be approved on Appstore) to detect when device passcode is activated on Home screen.

Basically, my app would like to know those phone events:

  1. device screen turn on/off
  2. phone lock/unlock (by Auto-Lock setting / press Power button)
  3. passcode activate (by Require Passcode setting)

As far as I research, I could achieve 1 & 2 by combine Darwin Notification Center & notify_get_state with 4 events:

 com.apple.springboard.lockstate
 com.apple.springboard.lockcomplete
 com.apple.springboard.hasBlankedScreen
 com.apple.iokit.hid.displayStatus

The problem I get is those events only tell me about lock / unlock state, not passcode state. Mean that if you require passcode after 5 mins, you can lock/unlock phone without passcode in first 4 mins.

I also know to there is a way to get both lock state & passcode state, by using SBGetScreenLockStatus(port, &locked, &passcode). But it's using private framework so it would be rejected by Apple.

From this topic (Programatically Checking if a Passcode Lock is Set) I only get if passcode is set on phone or not.

UPDATE: What I found is there is an event called back when passcode is in effected. com.apple.mobile.keybagd.lock_status but can't find any document about it. And it doesn't changed value when i use notify_get_state.

Community
  • 1
  • 1
nahung89
  • 7,745
  • 3
  • 38
  • 40

1 Answers1

1

I think you can find some private API to get it. However, most likely these won't be approved by Apple. There is a chance that they will miss it. However, they reject apps based on private API usage.

Victor Ronin
  • 22,758
  • 18
  • 92
  • 184
  • Exactly. That why I'm researching if is there anyway to achieve that with public API. But so far there is no result. – nahung89 Jul 01 '16 at 02:59
  • @nahung89 I would recommend looking into WiFi, Bluetooth and other networking API. It could be that they have some externalities which you can check to detect that a device was turned off. Maybe they switch to another mode or something like that. – Victor Ronin Jul 01 '16 at 17:00