How to end a call in CallKit

2020-03-01 19:44发布

问题:

This is not a give-me-code question, this is a feasibility question. If I initiate a phone call using CallKit, is it also possible to programmatically end it?

回答1:

Yes, we can do programmatically, but we have to keep the UUID for that call,

CXEndCallAction *endaction = [[CXEndCallAction alloc] initWithCallUUID:callUUID];
[cxcallcontrollerobject requestTransaction:[CXTransaction transactionWithActions:@[action]] completion:completion];


    + (CXTransaction *)transactionWithActions:(NSArray <CXAction *> *)actions { 
        CXTransaction *transcation = [[CXTransaction alloc] init]; 
        for (CXAction *action in actions) { 
           [transcation addAction:action]; 
        } 
        return transcation; 
 }

Hope this helps.



回答2:

In swift use the following code, uuidCallKit is the UUID of the current call that I'm having with me.

let controller = CXCallController()
let transaction = CXTransaction(action: 
CXEndCallAction(call: uuidCallKit))controller.request(transaction,completion: { error in })


回答3:

Close All Call (Swift4)

func endCall(call: UUID) {

    let endCallAction = CXEndCallAction(call: call)
    let transaction = CXTransaction(action: endCallAction)
    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
        }

        print("EndCallAction transaction request successful")

    }

}


标签: ios callkit