星空网 > 软件开发 > 操作系统

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

        

    }

    

}





原标题:IOS监听屏幕状态

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

餐厨品类市场:https://www.goluckyvip.com/tag/14612.html
巴基斯坦收款:https://www.goluckyvip.com/tag/14613.html
美国报复:https://www.goluckyvip.com/tag/14616.html
婴儿监控器:https://www.goluckyvip.com/tag/14617.html
Anker IPO:https://www.goluckyvip.com/tag/14618.html
产品质量:https://www.goluckyvip.com/tag/14619.html
去日本入住酒店,东西随意用却有一个特殊“要:https://www.vstour.cn/a/411241.html
中国有哪些著名的酒店品牌。:https://www.vstour.cn/a/411242.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流