iOS 鎖屏判斷

來源:互聯網
上載者:User

標籤:

iOS 鎖屏判斷

 

應用程式的單例類對象中得到應用程式委託的對象 

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

 

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

 

- (void)applicationWillResignActive:(UIApplication *)application 

   通知委託應用程式將進入非使用中,在此期間,應用程式不接收訊息或事件。

這個方法在使用者鎖住螢幕時,也會調用。

 

與之相適應的是應用程式重新被使用者開啟時的委託 方法。另外常用的就是記憶體不足的系統警告,此時會調用應用程式委託類的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);

}

iOS 鎖屏判斷

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.