iOS使用CXCallObserver监听电话接听与拨打

初始化

Swift 复制代码
import CallKit

class HomeViewController: UIViewController, CXCallObserverDelegate {
    public var cacheManager: TripCacheManager = TripCacheManager.init()

    override func viewDidLoad() {
        super.viewDidLoad()
        self.callObserver.setDelegate(self, queue: DispatchQueue.main)
    }
}

状态监听

Swift 复制代码
func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {
    print("call observer uuid: \(call.uuid)")
    print("outgoing(拨打):\(call.isOutgoing) onHold(待接通):\(call.isOnHold) hasConnected(接通):\(call.hasConnected) hasEnded(挂断):\(call.hasEnded)")
    }
}

该方法不能通过单一状态来判断当前状态,建议进行多值的判断。

取消监听

Swift 复制代码
self.callObserver.setDelegate(nil, queue: DispatchQueue.main)
相关推荐
sweet丶15 小时前
CocoaPods Podfile优化设置手册-持续更新
ios·架构
karshey1 天前
【IOS webview】h5页面播放视频时,IOS系统显示设置的icon
前端·ios
游戏开发爱好者81 天前
抓包工具有哪些?代理抓包、数据流抓包、拦截转发工具
android·ios·小程序·https·uni-app·iphone·webview
bybitq1 天前
Go函数闭包实战-复用函数
ios·golang·xcode
renke33641 天前
Flutter 2025 跨平台工程体系:从 iOS/Android 到 Web/Desktop,构建真正“一次编写,全端运行”的产品
android·flutter·ios
Zender Han1 天前
Flutter 中 AbsorbPointer 与 IgnorePointer 的区别与使用场景详解
android·flutter·ios
Digitally2 天前
3种简单方法备份 iPhone 短信
ios·iphone
2501_915921432 天前
Flutter App 到底该怎么测试?如何在 iOS 上进行测试
android·flutter·ios·小程序·uni-app·cocoa·iphone