一、定義兩個巨集//鎖屏通知#define NotificationOff CFSTR("com.apple.springboard.lockcomplete")//解鎖通知#define NotificationOn CFSTR("com.apple.springboard.hasBlankedSc...
一、定義兩個巨集
//鎖屏通知
#define NotificationOff CFSTR("com.apple.springboard.lockcomplete")
//解鎖通知
#define NotificationOn CFSTR("com.apple.springboard.hasBlankedScreen")
二、註冊屏幕監聽事件
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, ListeningScreenLockState, NotificationOff, NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, ListeningScreenLockState, NotificationOn, NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
三、屏幕監聽的事件
static void ListeningScreenLockState(CFNotificationCenterRef center,void* observer,CFStringRef name,const void* object,CFDictionaryRef userInfo)
{
NSString* screenState = (__bridge NSString*)name;
if ([screenState isEqualToString:(__bridge NSString*)NotificationOff]) {
NSLog(@"********鎖屏**********");
} else {
NSLog(@"********解鎖**********");
}
}