iOS 判断屏幕是否锁屏
2014-11-19 11:18
323 查看
测试环境:iOS6.1 device:iphone5
获取锁屏方式区分为2种方式:
第一种(需越狱):
这是copy的sina博客的。
第二种:
我们知道锁屏和解锁的时候,iOS系统会发送通知,根据搜索,大概有下面3种通知:
com.apple.iokit.hid.displayStatus
该通知系统日志会打印出来:Apr 27 14:50:47 Administratorteki-iPad
backboardd[69] <Notice>: Posting 'com.apple.iokit.hid.displayStatus' notifyState=0
具体分析就是锁屏后通知会发出消息,在屏幕变亮后,没有滑动解锁,系统也会发出该通知
com.apple.springboard.lockstate
该通知在系统锁屏和滑动解锁后,会发出该通知
com.apple.springboard.lockcomplete
对锁屏状态的获取,第一种方式是比较合适和简单的,如果想根据通知来获取,同样可以,代码如下:
state 的值就是锁屏的状态值。
0:锁屏
1:解锁
转载自:http://blog.csdn.net/feng3327/article/details/8859478
获取锁屏方式区分为2种方式:
第一种(需越狱):
if ([[objc_getClass("SBAwayController") sharedAwayController] isLocked]) { NSLog(@"double check Home ,now YES Lock"); } else{ NSLog(@"double check Home ,now NO Lock"); }
这是copy的sina博客的。
第二种:
我们知道锁屏和解锁的时候,iOS系统会发送通知,根据搜索,大概有下面3种通知:
com.apple.iokit.hid.displayStatus
该通知系统日志会打印出来:Apr 27 14:50:47 Administratorteki-iPad
backboardd[69] <Notice>: Posting 'com.apple.iokit.hid.displayStatus' notifyState=0
具体分析就是锁屏后通知会发出消息,在屏幕变亮后,没有滑动解锁,系统也会发出该通知
com.apple.springboard.lockstate
该通知在系统锁屏和滑动解锁后,会发出该通知
com.apple.springboard.lockcomplete
对锁屏状态的获取,第一种方式是比较合适和简单的,如果想根据通知来获取,同样可以,代码如下:
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, updateEnabled, CFSTR("com.apple.iokit.hid.displayStatus"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
static void updateEnabled(CFNotificationCenterRef center, void* observer, CFStringRef name, const void* object, CFDictionaryRef userInfo) { uint64_t state; int token; notify_register_check("com.apple.iokit.hid.displayStatus", &token); notify_get_state(token, &state); notify_cancel(token); NSLog(@"%llu",state); }
state 的值就是锁屏的状态值。
0:锁屏
1:解锁
转载自:http://blog.csdn.net/feng3327/article/details/8859478
相关文章推荐
- iOS device is locked/unlocked (判断手机屏幕是否锁屏)
- iOS 判断屏幕是否锁屏
- iOS判断UIView是否显示在屏幕上
- iOS 判断设备是否锁屏
- iOS 判断 UITableViewCell 和 UICollectionViewCell 是否移出屏幕
- ios--笔记--判断当前屏幕是否是iphone5的尺寸
- iOS判断UIView是否显示在屏幕上
- iOS判断UIView是否显示在屏幕上
- IOS根据屏幕尺寸判断是否为iphone6plus尺寸
- IOS之——判断设备是否越狱
- IOS判断设备是否已越狱(isJailbroken)
- 判断当前是否是锁屏状态
- IOS 判断是否首次启动APP
- [ios开发]判断网络连接是否正常
- iOS开发之回调delegate的方法时判断delegate是否已经被释放
- ios正则表达式判断邮箱格式是否正确
- ios判断图片是否完整
- 判断当前是否为锁屏界面(Keyguard)
- IOS判断设备是否已越狱(isJailbroken)
- Android(判断wifi是否开启,手机屏幕状态,sdcard是否被拔出,设置全屏)