1.首先引入CoreTelephony.framework
2.加入头文件 1 | # import < CoreTelephony / CTCallCenter . h > |
---|
3.功能实现
1 2 3 4 | CTCallCenter * center = [ [ CTCallCenter alloc ] init ] ; center . callEventHandler = ^ ( CTCall * call ) { NSLog ( @ "Call State : %@" , [ call description ] ) ; } ; |
---|
当电话打进来时,程序就会执行我们的block.
CTCall (0x1ab590) { callState: [CTCallStateIncoming] Call ID: [2B9E84A9-0F12-4539-AC8D-AF2A7ED7069E] } CTCall (0x183a00) { callState: [CTCallStateDisconnected] Call ID: [2B9E84A9-0F12-4539-AC8D-AF2A7ED7069E] } 注:__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0)