美文网首页
iOS 监听手机来电状态

iOS 监听手机来电状态

作者: TheLazyCoder | 来源:发表于2017-07-24 17:53 被阅读126次
    //CoreTelephony.framework
    
    #import  <CoreTelephony/CTCallCenter.h>
    
    #import <CoreTelephony/CTCall.h>
    
    @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 监听手机来电状态

          本文链接:https://www.haomeiwen.com/subject/yeobkxtx.html