iOS 监听手机来电状态

//CoreTelephony.framework

#import  

#import 

@property(nonatomic,strong)CTCallCenter*callCenter;

callCenter此参数必须为成员变量,要不然在ARC编译环境下,在这个函数之后就会被销毁,无法正常监听来电状态!

self.callCenter= [[CTCallCenteralloc]init];

self.callCenter.callEventHandler= ^(CTCall* call) {

if([call.callStateisEqualToString:CTCallStateDisconnected])

{

NSLog(@"Call has been disconnected");

}

elseif([call.callStateisEqualToString:CTCallStateConnected])

{

NSLog(@"Call has just been connected");

}

elseif([call.callStateisEqualToString:CTCallStateIncoming])

{

NSLog(@"Call is incoming");

}

elseif([call.callStateisEqualToString:CTCallStateDialing])

{

NSLog(@"call is dialing");

}

else

{

NSLog(@"Nothing is done");

}

};

你可能感兴趣的:(iOS 监听手机来电状态)