iosswiftxcodeswift4.2callkit

How do I end the call session on callkit from my custom ongoing call UI?


When a user end a call from the CallKit UI the app ends the call and the actual VOIP call also end. But when I end the call from my custom UI the VOIP call ends but the CallKit is still active. How do I end the CallKit session from my custom UI?

This is what happens when I press end call on the CallKit UI:

 func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
     XCPjsua.shared()?.endCall()
     action.fulfill()
 }

This is what happens when I end call from my custom UI (Should I close CallKit here?):

- (void)endcall {
    [[XCPjsua sharedXCPjsua] endCall];
}

Solution

  • If you want to end the call from your custom UI you should do that through a CXTransaction:

    let callController = CXCallController()
    
    let endCallAction = CXEndCallAction(call: aUUID)
    callController.request(
        CXTransaction(action: endCallAction),
        completion: { error in
            if let error = error {
                print("Error: \(error)")
            } else {
                print("Success")
            }
        })
    

    this will cause provider(_ provider: CXProvider, perform action: CXEndCallAction) to be called.

    In all other cases (i.e. remote ended, unanswered, etc... - see CXCallEndedReason) you should only report the ended call:

    let provider: CXProvider
    
    provider.reportCall(with: call.uuid, endedAt: Date(), reason: .remoteEnded)
    

    in this case provider(_ provider: CXProvider, perform action: CXEndCallAction) will not be called.