监听通话状态
#import <CoreTelephony/CTCallCenter.h>
#import <CoreTelephony/CTCall.h>
self.callCenter = [[CTCallCenteralloc] init];
WEAKSELF;
self.callCenter.callEventHandler = ^(CTCall* call) {
NSLog(@"callid %@",call.callID);
if ([call.callState isEqualToString:CTCallStateDisconnected])
{
NSLog(@"挂断了电话咯Call has been disconnected");
if(weakSelf.isTrueCall && weakSelf.currentContactPhoneOrder && weakSelf.isContactSuccess){
[weakSelf notificationServicePhoneState];
}else{
weakSelf.isTrueCall = NO;
weakSelf.isContactSuccess = NO;
}
}
else if ([call.callState isEqualToString:CTCallStateConnected])
{
NSLog(@"电话通了Call has just been connected");
if (weakSelf.isTrueCall) {
weakSelf.isContactSuccess = YES;
}
}
else if([call.callState isEqualToString:CTCallStateIncoming])
{
NSLog(@"来电话了Call is incoming");
}
else if ([call.callState isEqualToString:CTCallStateDialing])
{
NSLog(@"正在播出电话call is dialing");
weakSelf.isTrueCall = YES;
}
else
{
NSLog(@"嘛都没做Nothing is done");
}
};