美文网首页
iOS 来电监听

iOS 来电监听

作者: 摘心 | 来源:发表于2019-03-20 10:01 被阅读0次

    App 涉及到音频播放不可避免需要做系统来电处理。使用方法非常简单,但是不常用,有必要做个笔记方便使用时查看。
    1.引入系统头文件

    import <CoreTelephony/CTCallCenter.h>

    import <CoreTelephony/CTCall.h>

    2.声明来电监听对象
    @property(nonatomic, strong) CTCallCenter* callCenter;
    3.注册来电监听

    - (void)initCallCenter {
      _callCenter = [[CTCallCenter alloc] init];
      _callCenter.callEventHandler = ^(CTCall* call) {
        dispatch_async(dispatch_get_main_queue(), ^{
          if ([call.callState isEqualToString:CTCallStateDisconnected]) {
            NSLog("CTCallCenter:Call has been disconnected");
          } else if ([call.callState isEqualToString:CTCallStateConnected]) {
            NSLog("CTCallCenter:Callhasjustbeen connected");
          } else if ([call.callState isEqualToString:CTCallStateIncoming]) {
            NSLog("CTCallCenter:Call is incoming");
          } else if ([call.callState isEqualToString:CTCallStateDialing]) {
            NSLog("CTCallCenter:Call is Dialing");
          } else {
            NSLog("CTCallCenter:Nothing is done");
          }
        });
      };
    }
    

    相关文章

      网友评论

          本文标题:iOS 来电监听

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