Skip to content

Commit c464665

Browse files
committed
fix: sanity check on call state before CXEndCall transaction*
Calling `callKitCallController.request(CXEndCallAction)` with no matching call to UUID will result in the following error: > End Call Failed: The operation couldn’t be completed. > com.apple.CallKit.error.requesttransaction error 4 Using the CXCallObserverDelegate call observer, we can check if the call is present before requesting the transaction.
1 parent ee5b7a2 commit c464665

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ios/Classes/SwiftTwilioVoicePlugin.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,11 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
553553
}
554554
}
555555

556+
// Check if a call with a given UUID exists
557+
func isCallActive(uuid: UUID) -> Bool {
558+
return activeCalls[uuid] != nil
559+
}
560+
556561
func incomingPushHandled() {
557562
if let completion = self.incomingPushCompletionCallback {
558563
self.incomingPushCompletionCallback = nil
@@ -905,6 +910,13 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
905910

906911
self.sendPhoneCallEvents(description: "LOG|performEndCallAction method invoked", isError: false)
907912

913+
// check if call is still active, preventing a race condition ending the call throwing an End Call Failed transaction error 4 error
914+
guard isCallActive(uuid: uuid) else {
915+
print("Call not found or already ended. Skipping end request.")
916+
self.sendPhoneCallEvents(description: "Call Ended", isError: false)
917+
return
918+
}
919+
908920
let endCallAction = CXEndCallAction(call: uuid)
909921
let transaction = CXTransaction(action: endCallAction)
910922

0 commit comments

Comments
 (0)