项目中需要检测来电状态,使用了CTCallCenter,在AppDelegate中,代码如下:
CTCallCenter *callCenter = [[CTCallCenter alloc] init]; callCenter.callEventHandler = ^(CTCall *call) { if ([call.callState isEqualToString: CTCallStateDialing]){ NSLog(@"Call Dialing"); } if (call.callState == CTCallStateConnected){ NSLog(@"Call Connected"); } if (call.callState == CTCallStateDisconnected){ } };
可奇怪的是无论如何都不执行....来电接听挂断神马的根本不走Block.
找了半天度娘谷哥也无解.后来实然想到,把
CTCallCenter *callCenter写成了成员变量,然后就正常了...
原来是ARC模式下,一出代码块,callCenter就被释放了.