iOS监听电话事件
项目上有个需求,要求打完电话后加积分.
首先导入这两个头文件:
#import <CoreTelephony/CTCallCenter.h> #import <CoreTelephony/CTCall.h>
添加属性:
@property (nonatomic, strong) CTCallCenter *callCenter;
获取状态如下:
self.callCenter = [[CTCallCenter alloc] init]; self.callCenter.callEventHandler=^(CTCall* call) { if (call.callState == CTCallStateDisconnected) { NSLog(@"挂断电话Call has been disconnected"); } else if (call.callState == CTCallStateConnected) { NSLog(@"电话通了Call has just been connected"); } else if(call.callState == CTCallStateIncoming) { NSLog(@"来电话了Call is incoming"); } else if (call.callState ==CTCallStateDialing) { NSLog(@"正在播电话call is dialing"); } else { NSLog(@"Nothing is done"); } };
作者:洛洛爱吃肉 出处:http://www.cnblogs.com/dongliu/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 如果文中有什么错误,欢迎指出。以免更多的人被误导。