0

When a call is in progress (sent or received) the speakerphone is engaged already, and the speakerphone button does not react to presses to turn it off.

Is there a way to toggle it in code or enable it to be toggled in the UI? I believe this UI is Apple's core audio phone call UI.

This happens with Twilio's quickstart demo code from here: https://github.com/twilio/voice-quickstart-swift

dev4life
  • 1,150
  • 10
  • 13
  • Does this happen on more than one iPhone? – Andy Apr 20 '17 at 18:18
  • Yes, an iPhone 5s and iPhone 6. I guess more people have the issue too: http://stackoverflow.com/questions/37893672/twilio-client-voice-call-speaker-on-off-issue/37973032#37973032 but this answer didn't help me so far. – dev4life Apr 20 '17 at 21:44

4 Answers4

0

Try the following to force output to speaker:

if !session.overrideOutputAudioPort(AVAudioSessionPortOverride.Speaker, error:&error) {
   println("could not set output to speaker")
   if let e = error {
      println(e.localizedDescription)
   }
}
  • Thanks for trying, I updated my question to clarify that the speakerphone is actually already on and I want to turn it off. Any ideas there? – dev4life Apr 20 '17 at 16:42
0

SWIFT 3.0

try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionModeVoiceChat, options: .mixWithOthers)
try AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
try AVAudioSession.sharedInstance().setActive(true)

Overide output port to none.

krish
  • 3,856
  • 2
  • 24
  • 28
0

SWIFT 4

try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, mode: AVAudioSession.Mode.voiceChat, options: .mixWithOthers)
try AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
try AVAudioSession.sharedInstance().setActive(true)
LAD
  • 135
  • 5
  • 13
0

You can try below code snippet

func moveToVoiceCall() {

    audioDevice.block = {
        DefaultAudioDevice.DefaultAVAudioSessionConfigurationBlock()
        do {
            try AVAudioSession.sharedInstance().setMode(.voiceChat)
            try AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
        } catch {
            print(error)
        }
    }

    audioDevice.block();

}