iOS 鎖屏判斷

iOS 鎖屏判斷spring

 

應用程序的單例類對象中獲得應用程序委託的對象 app

UIApplicationDelegate* myDelegate = [[UIApplication sharedApplication] delegate];ui

 

UIApplication 接收到全部的系統事件和生命週期事件時,都會把事件傳遞給UIApplicationDelegate進行處理,對於用戶輸入事件,則傳遞給相應的目標對象去處理。spa

 

- (void)applicationWillResignActive:(UIApplication *)application server

   通知委託應用程序將進入非活動狀態,在此期間,應用程序不接收消息或事件。對象

這個方法在用戶鎖住屏幕時,也會調用。token

 

與之相適應的是應用程序從新被用戶打開時的委託 方法。另外經常使用的就是內存不足的系統警告,此時會調用應用程序委託類的applicationDidReceiveMemoryWarning()方法, 而後咱們就能夠試着釋放一些內存了。生命週期

 

 

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, updateEnabled, CFSTR("com.apple.iokit.hid.displayStatus"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);事件

    

    // 1狀態內存

    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, lockComplete, CFSTR("com.apple.springboard.lockcomplete"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);

    // 2狀態

    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, lockState, CFSTR("com.apple.springboard.lockstate"), 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);

}

 

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

    uint64_t state;

    int token;

    notify_register_check("com.apple.springboard.lockcomplete", &token);

    notify_get_state(token, &state);

    notify_cancel(token);

    NSLog(@"lockComplete狀態:%llu",state);

}

 

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

    uint64_t state;

    int token;

    notify_register_check("com.apple.springboard.lockstate", &token);

    notify_get_state(token, &state);

    notify_cancel(token);

    NSLog(@"lockState狀態:%llu",state);

}

相關文章
相關標籤/搜索