iosbluetoothavaudiosession

iOS Swift AVAudioSession - Changing Route to bluetooth explicitly


So I am in need of a requirement where I have to show, connected bluetooth device and play audio there, which currently I have done already. But say I want to switch from my bluetooth to Phones speaker, and connect back to bluetooth again after some point, can I do this? if not what would be my option to achieve this. Thanks


Solution

  • To switch routes, you will change the session's options. For example, to switch from Bluetooth to the internal speaker, you'll want to remove the .allowBluetoothA2DP option and likely add the .defaultToSpeaker option. To move back to A2DP Bluetooth, you would reverse the options. (If you need HFP rather than A2DP, use .allowBluetooth rather than .allowBluetoothA2DP.)