I am trying to override me application's audio to speaker when the user hits a button but speaker doesn't show as an available audioutput when airpods are connected. What can i do to make the sound go to speaker? This code works when any other bluetooth device is connected.
po AVAudioSession.sharedInstance().availableInputs
AVAudioSessionPortDescription: 0x283dc3410, type = MicrophoneBuiltIn; name = iPhone Microphone; UID = Built-In Microphone; selectedDataSource = (null)> VAudioSessionPortDescription: 0x283dc32b0, type = BluetoothHFP; name = Lindsey’s AirPods; UID = 94:B0:1F:C3:FF:6B-tsco; selectedDataSource = (null)>
var err: Error? = nil
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSession.Category.playAndRecord, mode: .voiceChat, options: [.allowBluetooth, .allowBluetoothA2DP, .mixWithOthers])
} catch {
NSLog("Unable to change audio category because : \(String(describing: err?.localizedDescription))")
err = nil
}
do {
try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
} catch let error as NSError {
print("audioSession error turning on speaker: \(error.localizedDescription)")
}