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

            

        }

        

    }


  • 相关阅读:
    Zepto
    html5新增表单控件和表单属性
    初识html5
    H5 css3布局
    H5 css3背景透明度
    H5 css3特效
    H5 css3渐变
    H5css3的文本属性
    一个类有两个类别中,在类别里实现了相同的方法结果?
    size_t 理解误区
  • 原文地址:https://www.cnblogs.com/lfgtechblog/p/5160924.html
Copyright © 2011-2022 走看看