初始化
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)