3

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];
}
Marco
  • 1,572
  • 1
  • 10
  • 21
Coder_98
  • 117
  • 3
  • 10

3 Answers3

11

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.

mykolaj
  • 974
  • 8
  • 17
Marco
  • 1,572
  • 1
  • 10
  • 21
  • Do you mean I only use `CXTransaction` if I'm calling (should have called CXStartCallAction)? – Elsammak May 13 '19 at 08:04
  • 1
    @Elsammak I mean that if the user wants to end a call (e.g. through the end call button), regardless of the fact that he started or not the call, you should use `CXTransaction`. In all the other cases, i.e. the call has ended for a reason not depending on a user action, you should just report the end of the call to the `CXProvider`. – Marco May 13 '19 at 10:01
  • 1
    Thank you, I've been in this issue like 2 days. Always get error 4 which means no such call UUID exists although it is. Calling just reportCall works as charm (y) – Elsammak May 14 '19 at 04:32
2

I use this code to close call

provider?.reportCall(with: PushUtility.shared.uuid!, endedAt: Date(), reason: .remoteEnded)

First save your uuid which you are using for connecting call use that uuid for end call.

Ali Aqdas
  • 437
  • 5
  • 9
1

I managed to close it using the reportCall function

 provider?.reportCall(with: appG.uuid, endedAt: Date(), reason: .remoteEnded)

So I just call that function when I press end call from my custom UI

Coder_98
  • 117
  • 3
  • 10