twilio / voice-quickstart-ios

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

Connecting to audio in a call returns The operation couldn’t be completed. (OSStatus error -50.) #555

Open rakefetWorkiz opened 7 months ago

rakefetWorkiz commented 7 months ago

Description

Once in a while making an outbound call doesn't connect the audio in the device. Trying later during the call to change audio port throws error The operation couldn’t be completed. (OSStatus error -50.)

try audioSession.overrideOutputAudioPort(isMicOn ? .speaker : .none)

Since this happened we tried according to some articles we found to implement a recovery using the following code:

try audioSession.setMode(.voiceChat)
try audioSession.setCategory(.playAndRecord)
try audioSession.overrideOutputAudioPort(.speaker : .none)

but this action also fails with the same error.

This is very hard to reproduce so we weren't able to debug a solution, but when it does happens it really bothers our clients.

Is there any advice for anything we can do to either avoid this error or to recover from it after it happens?

Steps to Reproduce

I am not sure what exact steps can reproduce this, though from what I saw it only happens with outgoing calls.

Reproduces How Often

Happens about twice a day for the affected users

Twilio Call SID(s)

CA77581c11071259972cbee70785ec126c, CA77581c11071259972cbee70785ec126c, CA77581c11071259972cbee70785ec126c

*the examples are all from the same client that is very troubled by this issue

Logs

  Workiz              0x10067340c  VoiceManager.setDefaultAudioRoute (VoiceActions.swift:229)
  Workiz              0x100c35760  VoiceManager.provider (VoiceProviderDelegate.swift:26)
  Workiz              0x100c346a4  VoiceManager.provider
  CallKit             0x1c399425c  __57-[CXProvider handleAudioSessionActivationStateChangedTo:]_block_invoke
  libdispatch         0x1aa8c76a4  _dispatch_call_block_and_release
  libdispatch         0x1aa8c92fc  _dispatch_client_callout
  libdispatch         0x1aa8d7994  _dispatch_main_queue_drain
  libdispatch         0x1aa8d75ac  _dispatch_main_queue_callback_4CF
  CoreFoundation      0x1a290d018  __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
  CoreFoundation      0x1a2909d24  __CFRunLoopRun
  CoreFoundation      0x1a2909474  CFRunLoopRunSpecific
  GraphicsServices    0x1e5e624f4  GSEventRunModal
  UIKitCore           0x1a4d2d628  -[UIApplication _run]
  UIKitCore           0x1a4d2cc64  UIApplicationMain

In our breadcrumbs we usually have something like that:

Error starting audio session The operation couldn’t be completed. (OSStatus error -50.)
Setting audio route to voice chat
provider did activate
POST https://eventgw.twilio.com/v4/EndpointEvents [200] -- (few more of those)
Call started ringing
POST https://eventgw.twilio.com/v4/EndpointEvents [200] -- (usually few of those)
{ action: UIKeyboardDidHideNotification }
provider start call action
Reporting call to CallKitProvider

Versions

Voice iOS SDK

6.10.0 via CocoaPods

Xcode

15.2

iOS Version

17.x (most of them are from 17.2.1)

iOS Device

A lot of different versions, most of them relatively new (14, 14 pro max, 13, etc)

bobiechen-twilio commented 7 months ago

Thanks for reaching out @rakefetWorkiz. We will have a look and try to reproduce and investigate.

rakefetWorkiz commented 6 months ago

@bobiechen-twilio have you been able to find something?