zoukankan      html  css  js  c++  java
  • IOS监听屏幕状态

    一、定义两个宏

     

    //锁屏通知

    #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(@"********解锁**********");

            

        }

        

    }


  • 相关阅读:
    继承
    包、logging模块、hashlib模块、openpyxl模块、深浅拷贝
    Java中的Lambda表达式
    Java中udp/tcp的发送和接收
    Java中的IO流总结
    Java中的多线程
    Java中使用try-catch-finally处理IO流中的异常
    Java中的杂流(闸总)
    Java中的Properties
    Java中IO流之字符流
  • 原文地址:https://www.cnblogs.com/lfgtechblog/p/5160924.html
Copyright © 2011-2022 走看看