一代天骄丶蛋蛋

导航

IOS开发:监听来电状态的改变。

 

 

#import <CoreTelephony/CTCallCenter.h>

#import <CoreTelephony/CTCall.h>

 

@property(nonatomic,strong)CTCallCenter *callCenter;

 

以下代码写在didFinishLaunchingWithOptions中。

必须将callCenter声明为成员变量,否则无法监听。

 

self.callCenter = [[CTCallCenter alloc] init];

    self.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");  

        }  

    };

posted on 2016-05-30 09:35  一代天骄丶蛋蛋  阅读(1375)  评论(0编辑  收藏  举报