Audio is not working for voip call after gsm calls ends by another user

96 Views Asked by At

I am working on audio/video call implementation and it is working fine. So now I am working on scenario when my voip calls gets interrupted by gsm call. When I receive any gsm call I get End/Answer and Hold/accept option in callkit.

When I select Hold/accept option my calls gets hold by calling CXSetHeldCallAction method and I paused/muted my video/audio and at the same time iOS deactivate audio session by calling didDeactivate audioSession method which is expected behaviour.

Now if I end the gsm call from my end by tapping end call button from callkit my audio session gets activated automatically and also I resume my video and audio. But the same is not happening if another user ends the call and no audio session gets activated and so audio is not working in this case.

I check different stack overflow answers and tried everything possible but still couldn't able to figure out the solution. I even tried to activated the session manually but got session activation failed error. So if anyone have faced the same issue and solved the issue please give me an idea how can I do that.

1

There are 1 best solutions below

0
rauldhasmana On

After hours of debugging I resolved the issue. I implemented a CXCallObserver delegate callChanged, where I checked if another call gets ended or not with the help of my voip call id. If another call gets ended, I call CXSetHeldCallAction to unhold my voip call and, in this way, the audio session got restored automatically.

func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {
    guard let callId = voipCallId else { return }
    //check if another call got ended. if yes then unhold voip call
    if call.uuid != callId && call.hasEnded {
        let callController = CXCallController()
        let update = CXCallUpdate()
        let endCallAction = CXSetHeldCallAction(call: callId, onHold: false)
        callController.request(
            CXTransaction(action: endCallAction),
            completion: { error in
                if let error = error {
                    debugPrint("call unheld Error: \(error.localizedDescription)")
                } else {
                    debugPrint("call unheld Success")
                    //restore original video and mute status of call.
                    CallManager.shared.isShowVideo = self.originalIsShowVideoStatus
                    CallManager.shared.isMuteAudio = self.originalIsMuteAudioStatus
                    self.provider?.reportCall(with: callId, updated: update)
                }
            })
    }
}