iOS 系统打电话事件的监听与状态获取

导入CoreTelephony.framework

@property (nonatomic, strong) CTCallCenter *callCenter;

这个一定要声明为属性,如果在某个函数中做声明的话,ARC就会自动在函数执行结束的时候将其释放掉。

#import   
#import   
@property (nonatomic, strong) CTCallCenter *callCenter;  
CTCallCenter *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");  
        }    
    };  

call.callState 这个属性记录了电话操作的状态,具体都有哪些值可以通过头文件得知。

你可能感兴趣的:(iOS 系统打电话事件的监听与状态获取)