I am working on a Voip app, which integrates with CallKit. I need to handle audio routing between integrated speaker/"loud" speaker/wired headset/BT headsets.
I am configuring the audiosession like this:
I listen to AVAudioSessionRouteChangeNotification and update a button to reflect the currently selected device.
It all works nicely. But I also want the button to show a list of available devices and to be able to pick between them.
The list is there and when the user selects one, I call setPreferredInput on AVAudioSession, or overrideOutputAudioPort, if it is the "loud" speaker which should be active.
The audio routing is properly performed and audio is coming out where I would expect it.
BUT... the iOS control center does not reflect the changes, it might show the internal speaker as selected, when in fact the audio is coming over Bluetooth.
Also, the AVAudioSessionRouteChangeNotification will not notify correctly if the Airpods are put back in the box, as it seems iOS still believes the internal speaker is used and therefore does not consider it a route change that the Airpods are no longer available.
Now I have started using AVRoutePickerView instead of my own custom menu, and I don't have the same problem. Everything is now in sync.
So my question is - is this a known limitation?
Is it in fact a requirement to use AVRoutePickerView, if you want to change the audio routing of a voip app during a call?
Or should it be possible to do this with my custom UI, but maybe I am doing something else wrong, when changing the AVAudioSession?
I am configuring the audiosession like this:
Code Block [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord mode:AVAudioSessionModeVoiceChat options:AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP | AVAudioSessionCategoryOptionAllowAirPlay error:&err];
I listen to AVAudioSessionRouteChangeNotification and update a button to reflect the currently selected device.
It all works nicely. But I also want the button to show a list of available devices and to be able to pick between them.
The list is there and when the user selects one, I call setPreferredInput on AVAudioSession, or overrideOutputAudioPort, if it is the "loud" speaker which should be active.
The audio routing is properly performed and audio is coming out where I would expect it.
BUT... the iOS control center does not reflect the changes, it might show the internal speaker as selected, when in fact the audio is coming over Bluetooth.
Also, the AVAudioSessionRouteChangeNotification will not notify correctly if the Airpods are put back in the box, as it seems iOS still believes the internal speaker is used and therefore does not consider it a route change that the Airpods are no longer available.
Now I have started using AVRoutePickerView instead of my own custom menu, and I don't have the same problem. Everything is now in sync.
So my question is - is this a known limitation?
Is it in fact a requirement to use AVRoutePickerView, if you want to change the audio routing of a voip app during a call?
Or should it be possible to do this with my custom UI, but maybe I am doing something else wrong, when changing the AVAudioSession?