使用另一个答案中的以下代码来检测电话状态,它可以正常工作,但是现在我需要创建一个func,在该函数中,以编程方式关闭电话10秒钟后, 或放置一个按钮以使用户关闭它。 甚至可以检测到用户按下红色按钮。
代码
// CXCallController.request(transaction) { error in
便笺是否有效
立即测试:
func endCall(call: UUID) {
let endCallAction = CXEndCallAction(call: call)
let transaction = CXTransaction(action: endCallAction)
let cxcontrolelr = CXCallController()
// CXCallController.request(transaction) { error in
// if let error = error {
// print("EndCallAction transaction request failed: \(error.localizedDescription).")
// self.cxCallProvider.reportCall(with: call, endedAt: Date(), reason: .remoteEnded)
// return
// }
CXCallController.requestTransaction(cxcontrolelr)
print("EndCallAction transaction request successful")
}
}
func closeTheCAll() {
// let myUuid = UIDevice.current.identifierForVendor?.uuidString
let myUuid = UUID().uuidString
print(myUuid)
endCall(call: myUuid)
}
//MARK: Monitoring call status section //this is working with no issue
func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {
if call.hasEnded == true {
print("Disconnected")
}
if call.isOutgoing == true && call.hasConnected == false {
print("Dialing")
}
if call.isOutgoing == false && call.hasConnected == false && call.hasEnded == false {
print("Incoming")
}
if call.hasConnected == true && call.hasEnded == false {
print("Connected")
}
}