iPhone在Darwin层上建立Notification监听的方法

来源:互联网 发布:网络平台教师兼职 编辑:程序博客网 时间:2024/06/09 18:12

iPhone在Darwin层上建立Notification监听的方法

作者:wangzz
原文地址:http://blog.csdn.net/wzzvictory/article/details/8561705
转载请注明出处
如果觉得文章对你有所帮助,请通过留言或关注微信公众帐号wangzzstrive来支持我,谢谢!

在Darwin层上建立Notification监听的方法:


CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),//center

                                    NULL, // observer

                                    hasBlankedScreen,// callback

                                    CFSTR("com.apple.springboard.lockstate"),// event name

                                    NULL, // object

                                    CFNotificationSuspensionBehaviorDeliverImmediately);



回调函数可以这样写:

static void hasBlankedScreen(CFNotificationCenterRef center,void *observer,CFStringRef name,constvoid *object, CFDictionaryRef userInfo)

{

    NSString* notifyName = (__bridgeNSString*)name;

    NSLog(@"notify name:%@",notifyName);

}


该监听方法可以实现很多系统事件或自定义事件的捕获,比如本次我们监听的事件名:com.apple.springboard.lockstate,就是用来监听屏幕的上锁和打开。

初步确定该方法需要在越狱手机上使用,如有新的了解,会继续更新