IOS监听通话状态(私有API)

来源:互联网 发布:淘宝宝贝描述尺寸 编辑:程序博客网 时间:2024/06/11 19:48
头文件 在这里需要包含两个头文件,不需要导入framwork
#import "DetailViewController.h"
#import <CoreTelephony/CTCallCenter.h>
#import <CoreTelephony/CTCall.h>
@interfaceDetailViewController () <UIWebViewDelegate>
@property (nonatomic,strong) CTCallCenter *callCenter;
@end

//这是两种打电话的方式
- (IBAction)phoneAction:(id)sender {  
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];
}
- (IBAction)phoneWebAction:(id)sender {  
UIWebView *callWebview =[[UIWebView alloc] init] ;  
NSURL *telURL =[NSURL URLWithString:@"tel://514091"];  
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];  
[self.view addSubview:callWebview];
}

//这是电话的回调函数
-(void)detectCall{  
self.callCenter = [[CTCallCenter alloc] init];
self.callCenter.callEventHandler=^(CTCall* call) 
{  
if (call.callState == CTCallStateDisconnected)  
{NSLog(@"-----------------------------挂断");//挂断//self.viewController.signalStatus=YES;  
}elseif (call.callState == CTCallStateConnected){
NSLog(@"-----------------------------连通了");//联通了  
}elseif(call.callState == CTCallStateIncoming){  
NSLog(@"Call is incoming??????????1");
//self.viewController.signalStatus=NO;
}elseif (call.callState ==CTCallStateDialing){
NSLog(@"-----------------------------拨号");//拨号 
}else{
NSLog(@"Nothing is done????????????2");  
}
};
}