twilio / voice-quickstart-ios

Twilio Voice Quickstart for iOS with Swift
MIT License
182 stars 96 forks source link

Issue trying to hang up when answering an incoming call #499

Closed javyduty closed 2 years ago

javyduty commented 2 years ago

Description

When a call comes in from a push notification the delegate handles the call and changes the root view controller to the a call view controller (as expected). When trying to hang up the call using the performEndCallAction function I get the following error com.apple.CallKit.error.requesttransaction error 4. I have verified that the call uuid matches everywhere and have ensured there are no nils.

Steps to Reproduce

  1. Place call from one Quickstart app
  2. Answer call on second Quickstart app where the call is answered but forwarded to another view using (Scene Delegate)
  3. When trying to hang up call, error

Code

let storyBoard : UIStoryboard = UIStoryboard(name: "Calls", bundle: nil)
let audioCallView = storyBoard.instantiateViewController(withIdentifier: "AudioCalls") as! AudioCalls

window?.rootViewController = audioCallView
window?.makeKeyAndVisible()

//extension on the same view controller for accessing Scene Delegate

extension UIViewController {
    var window: UIWindow? {
        if #available(iOS 13, *){
            guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
                  let delegate = windowScene.delegate as? SceneDelegate, let window = delegate.window else { return nil }
            return window
        }
    }
}

Expected Behavior

call hangs up

Actual Behavior

Get this error com.apple.CallKit.error.requesttransaction error 4. Call is not working (can't hear or speak) but the call is still active (green indicator in corner)

Reproduces How Often

100%

Twilio Call SID(s)

CAe8e6ac6e7720850bf934d108e07f5ed1 CA66eab086af8feb32270f31692cf54c8a

CA8e9722adb056e49ec75ca6b75de16430 CA41dc1b81c23e5fb6a80a8cad59620298

Logs

pushRegistry:didReceiveIncomingPushWithPayload:forType:completion:
callInviteReceived:
providerDidBegin
Incoming call successfully reported.
provider:performAnswerCallAction:
providerDidBegin
callDidConnect:
provider:didActivateAudioSession:
 EndCallAction transaction request failed: The operation couldn’t be completed. (com.apple.CallKit.error.requesttransaction error 4.).
2022-04-15 19:08:27.983318+0200 Shmusik[630:56558] providerDidReset:

Versions

Swift: 5.4

Voice iOS SDK

6.3.1

Xcode

Xcode: Version 13.2.1

iOS Version

iOS 15

iOS Device

iPhone X - Two of them Simulator

bobiechen-twilio commented 2 years ago

Hi @javyduty

CallKit request error 4 typically means the UUID submitted in the request does not match anything that was previous reported to CallKit. Please check if the call UUID was properly reported to CallKit. The quickstart should provide a good example of such process.

By the way, does this happen when the incoming call is hung up by the caller or by the local client?

javyduty commented 2 years ago

Thanks for the response @bobiechen-twilio, it happens when hanging up from the local client (the person who answered the call) Hanging up works when using Call Kit (opening the recent apps and hanging up from the Call Kit view). It also works when hanging up from the caller. At times it is the only way to hang up.

bobiechen-twilio commented 2 years ago

Thanks @javyduty. In that case I think this flag might help: https://github.com/twilio/voice-quickstart-ios/blob/master/SwiftVoiceQuickstart/ViewController.swift#L133

javyduty commented 2 years ago

Would that need to be switched to false, since the person is receiving the call rather than the one initiating it?

bobiechen-twilio commented 2 years ago

We added the flag to differentiate the case when the disconnect is initiated via application UI, from the case when the disconnect happens from CallKit. In general you will want to make sure the disconnect procedure goes through the CallKit request and update call UUIDs consistently.

javyduty commented 2 years ago

Thanks, I will try that and let you know.

javyduty commented 2 years ago

I tried that but still no luck, I went a different route and had to move everything to a singleton and set the delegate in the view that I was calling. It now hangs up as expected. Just thought I would post in case anyone else ran into the same issue. Thanks for the help!