Audio not switching to speaker when airpods connected

349 Views Asked by At

I have airpods connected to my device and I am trying to switch the audio to speaker. I am using the code below which works when nothing is attached, other bluetooth devices are connected and when headphones are plugged in but it doesn't when there are airpods connected.

 do {
       try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
                } catch let error as NSError {
                    print("audioSession error turning on speaker: \(error.localizedDescription)")
                } 
0

There are 0 best solutions below