應用鎖屏 /解鎖 操做監聽

相關宏定義:spring

#define NotificationLock CFSTR("com.apple.springboard.lockcomplete")app

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

#define NotificationPwdUI CFSTR("com.apple.springboard.hasBlankedScreen")視頻

 

 

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

    [self addScreenStatusObserve];  // 視頻鎖屏監聽it

    /*io

     應用程序自身代理的方法直接寫需求便可。方法以下:後臺

    

     // 進入前臺object

    1. - (void)applicationWillEnterForeground:(UIApplication *)application程序

    

     // 非活動狀態,會在後臺保持一段時間,再將程序殺死

    2. - (void)applicationDidBecomeActive:(UIApplication *)application

 

     */

    return YES;

}

 

 

- (void)addScreenStatusObserve {

    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 if ([lockstate isEqualToString:(__bridge  NSString*)NotificationChange]) {

        

        NSLog(@"lock state changed.");

        

    }

    

}

相關文章
相關標籤/搜索