AVAudioSession.RouteChangeReason not detecting connected bluetooth headset/earphones

740 Views Asked by At

I'm working on a voice calling app for iOS in Swift and I need to enable auto detection and auto connection of wireless(bluetooth) headsets/earpeaces.

I'm using AVAudioSession RouteChangeReason but it's not detecting when airpods or some other wireless headset is connected via bluetooth. After connecting the device I can even see it in Bluetooth settings that it's connected, but the device is not listed in MPVolumeView as you can see in the screenshoot.

I've been looking for an answer on how to work this out all over the internet and even though there are a lot of similar questions here on StackOverFlow none of them is specifically related to my case so please give me a light on how to solve this.

2

There are 2 best solutions below

1
On BEST ANSWER

I just read the code and finally found what was wrong with it. The problem was that I was setting the category more than once so for some reason this was causing wireless headset/earpeace to not connect directly to the app.

9
On

.allowBluetoothA2DP is not valid for playAndRecord. You can't record over A2DP. Remove that one. Note that when you do this, if the user is listening to music, the quality is going to drop dramatically (it's possible that AirPods have a proprietary work around for that; I haven't played with them in this mode). In order to record over Bluetooth you have to use HFP, which provides basically "telephone" quality audio.