iOS 判断屏幕是否锁屏
2013-04-27 16:11
405 查看
测试环境: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 的值就是锁屏的状态值。
获取锁屏方式区分为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 的值就是锁屏的状态值。
相关文章推荐
- iOS 判断屏幕是否锁屏
- iOS device is locked/unlocked (判断手机屏幕是否锁屏)
- IOS根据屏幕尺寸判断是否为iphone6plus尺寸
- iOS 判断设备是否锁屏
- iOS判断UIView是否显示在屏幕上
- ios--笔记--判断当前屏幕是否是iphone5的尺寸
- iOS判断UIView是否显示在屏幕上
- iOS判断UIView是否显示在屏幕上
- iOS 判断 UITableViewCell 和 UICollectionViewCell 是否移出屏幕
- iOS 判断某一日期是否在一日期区间
- iOS - 正则表达式判断邮箱、身份证..是否正确
- ios判断某个坐标是否在某块区域内方法
- 【iOS知识学习】_如何判断手机是否为静音模式
- IOS动态判断UITextField是否输入为手机号
- JS判断客户端是否是iOS或者Android手机移动端
- iOS判断邮箱,手机号码,车牌号是否合法
- iOS判断是否有权限访问相机,相册,定位
- IOS开发中判断字符串是否为空字符的方法
- js判断客户端是否是IOS系统
- 判断屏幕是否解锁