1.调用系统电话
///调用系统电话
- (void)onClickOpenTelPhone:(NSString*)telPhoneNumber {
NSURL *telURL =[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", telPhoneNumber]];
[[UIApplication sharedApplication] openURL:telURL];
}
2.监听打电话状态
导入(CoreTelephony/CTCallCenter.h)和(CoreTelephony/CTCall.h)头文件
//1.CTCallCenter *_callCenter;//必须声明属性或者实例变量,要不不会回调block
//2.初始化监听变量
- (void)initCoreTelephoneCTCall {
_callCenter = [[CTCallCenter alloc]init];
_callCenter.callEventHandler = ^(CTCall* call){
if ([call.callState isEqualToString:CTCallStateDisconnected]) {
NSLog(@"挂断了电话咯Call has been disconnected");
} else if ([call.callState isEqualToString:CTCallStateConnected]) {
NSLog(@"电话通了Call has just been connected");
} else if([call.callState isEqualToString:CTCallStateIncoming]) {
NSLog(@"来电话了Call is incoming");
} else if ([call.callState isEqualToString:CTCallStateDialing]) {
NSLog(@"正在播出电话call is dialing");
} else {
NSLog(@"嘛都没做Nothing is done");
}
};
}