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

            

        }

        

    }


  • 相关阅读:
    http
    python的列表生成式
    flask的登陆验证
    脚本更新流程
    k8s中job和pod的区别
    k8s中一些常见概念
    supervisord部署和使用
    flask中config
    python类的继承super()的使用
    python中类的继承
  • 原文地址:https://www.cnblogs.com/lfgtechblog/p/5160924.html
Copyright © 2011-2022 走看看