iOS SDK提供了CoreTelephony.framework框架来处理一些关于电话的API。
首先<pre><code>@import CoreTelephony; </pre></code>
其次<pre><code>@property (nonatomic, strong) CTCallCenter *callCenter;</pre></code>
一定要强引用,否则会被释放导致不起作用
最后
<pre><code>
self.callCenter = [[CTCallCenter alloc] init];
self.callCenter.callEventHandler = ^(CTCall* call) {
if (call.callState == CTCallStateIncoming) {
NSLog(@"来电");
}else if (call.callState == CTCallStateDialing) {
NSLog(@"呼出");
}else if (call.callState == CTCallStateConnected) {
NSLog(@"接通");
}else if (call.callState == CTCallStateDisconnected) {
NSLog(@"断开");
};
};
</pre></code>
该回调为子线程回调,所以如果需要处理UI,切记回到主线程