twilio / voice-quickstart-ios

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

iOS App crashes when accepting the call from terminated state #524

Closed liyamahendra closed 1 year ago

liyamahendra commented 1 year ago

Description

When the app is in terminated state, and an incoming call is received, the app correctly detects the incoming call. But as soon as you try to connect, the app crashes. See the crash details from TestFlight, I see that it crashed at this line

  TwilioVoiceSDK.audioDevice = self.audioDevice;
image

Steps to Reproduce

  1. Make sure the PKPushRegistry is properly registered and app can receive incoming calls
  2. Force close the app
  3. Now call the Twilio number to get an incoming call
  4. Accept the incoming call - notice the crash as soon as the call is accepted

Code

CXProviderConfiguration *configuration = [[CXProviderConfiguration alloc] initWithLocalizedName:@"FreedomSoft"];
    configuration.maximumCallGroups = 1;
    configuration.maximumCallsPerCallGroup = 1;

    if (self.callKitProvider) {
        [self.callKitProvider invalidate];
    }

    self.callKitProvider = [[CXProvider alloc] initWithConfiguration:configuration];
    [self.callKitProvider setDelegate:self queue:nil];

    self.callKitCallController = [[CXCallController alloc] init];
    self.audioDevice = [TVODefaultAudioDevice audioDevice];
    TwilioVoiceSDK.audioDevice = self.audioDevice;
    TwilioVoiceSDK.logLevel = TVOLogLevelAll;
    self.activeCallInvites = [NSMutableDictionary dictionary];
    self.activeCalls = [NSMutableDictionary dictionary];
    self.playCustomRingback = NO;

    self.pushKitEventDelegate = self;
    [self initializePushKit];

Expected Behavior

App should not crash when trying to accept the incoming call, even when the call is accepted from terminated state

Actual Behavior

The app crashes when the incoming call is accepted from terminated state

Reproduces How Often

All the time, consistently.

Twilio Call SID(s)

You can find the Call SID in the SDK from TVOCall.sid or TVOCallInvite.callSid. The Call SID can also be found on the Twilio Calls Console: https://www.twilio.com/console/voice/calls/logs.

Logs

image

Versions

Voice iOS SDK

6.5.0 via CocoaPods

Xcode

Version 14.2 (14C18)

iOS Version

iOS Version: 16.3

iOS Device

iPhone 12

bobiechen-twilio commented 1 year ago

Hi @liyamahendra

Any chance you were able to see the detail in the Xcode debugger when the exception happened? From the stack in the screenshot very likely the exception was raised because audio device was assigned while the media factory already had been assigned with an audio device.

liyamahendra commented 1 year ago

Any chance you were able to see the detail in the Xcode debugger when the exception happened?

I can connect my device to Xcode and check the stack trace, if that would help?

From the stack in the screenshot very likely the exception was raised because audio device was assigned while the media factory already had been assigned with an audio device.

What does that mean please?

bobiechen-twilio commented 1 year ago

@liyamahendra if this is reproducible in your local dev environment with Xcode debugger attached, you should be able to see from the debug messages, which should have the information about the exception.

The SDK keeps a reference to the audio device internally and does not allow assigning another audio device while there is already one. This is very likely the cause of the exception based on the stacktrace in your screenshot. Please make sure there is no more than one TwilioVoiceSDK.audioDevice = yourAudioDevice in the application.