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");
}
});
};
}
网友评论