您的位置:首页 > 移动开发 > IOS开发

iOS开发之检测设备锁屏

2015-09-02 12:05 302 查看
#define NotificationLock CFSTR("com.apple.springboard.lockcomplete")

#define NotificationChange CFSTR("com.apple.springboard.lockstate")

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[self lookLockScreen];

return YES;

}

- (void)lookLockScreen
{
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, screenLockStateChanged, NotificationLock, NULL, CFNotificationSuspensionBehaviorDeliverImmediately);

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, screenLockStateChanged, NotificationChange, NULL, CFNotificationSuspensionBehaviorDeliverImmediately);

}

static void screenLockStateChanged(CFNotificationCenterRef center,void* observer,CFStringRef name,const void* object,CFDictionaryRef userInfo)

{

NSString* lockstate = (__bridge NSString*)name;

if ([lockstate isEqualToString:(__bridge  NSString*)NotificationLock]) {

//锁屏
NSLog(@"locked.");

} else {
//锁屏状态改变
NSLog(@"lock state changed.");

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: