问题
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:
- device screen turn on/off
- phone lock/unlock (by Auto-Lock setting / press Power button)
- 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
.
回答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.
来源:https://stackoverflow.com/questions/38035617/detect-passcode-lock-state-from-home-screen