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

头文件 在这里需要包含两个头文件,不需要导入framwork
#import "DetailViewController.h"
#import
#import
@interface DetailViewController () < 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;  
} else if (call .callState == CTCallStateConnected){
NSLog (@ "-----------------------------连通了" ); //联通了  
} else if (call .callState == CTCallStateIncoming){  
NSLog (@ "Call is incoming??????????1" );
//self.viewController.signalStatus=NO;
} else if (call .callState ==CTCallStateDialing){
NSLog (@ "-----------------------------拨号" ); //拨号  
} else {
NSLog (@ "Nothing is done????????????2" );  
}
};
}

你可能感兴趣的:(IOS开发)