Detect passcode lock state from Home screen

别等时光非礼了梦想. 提交于 2019-12-08 09:39:33

问题


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.


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!