如何监听电话状态

[plain] view plaincopy
#import <CoreTelephony/CTCallCenter.h>  
#import <CoreTelephony/CTCall.h>  

[plain] view plaincopy
-(void)detectCall  
{  
     CTCallCenter *callCenter = [[CTCallCenter alloc] init];  
    callCenter.callEventHandler=^(CTCall* call)  
    {  
        if (call.callState == CTCallStateDisconnected)  
        {  
            NSLog(@"Call has been disconnected");  
            self.viewController.signalStatus=YES;  
        }  
        else if (call.callState == CTCallStateConnected)  
        {  
            NSLog(@"Call has just been connected");  
        }  
          
        else if(call.callState == CTCallStateIncoming)  
        {  
            NSLog(@"Call is incoming");  
            //self.viewController.signalStatus=NO;  
        }  
          
        else if (call.callState ==CTCallStateDialing)  
        {  
            NSLog(@"call is dialing");  
        }  
        else  
        {  
            NSLog(@"Nothing is done");  
        }  
    };  
}  

你可能感兴趣的:(如何监听电话状态)