We are developing a VoIP application. Application is developed using Xamarin.iOS. In order to match iOS calling features, CallKit and AVRoutePickerView are used.
When VOIP call is connected, user try to switch the audio mode from Bluetooth to Earpiece and it is not switching in iOS 15 and above. AirPlay UI also not changing from Bluetooth to Earpiece and audio also not changed to Earpiece. We have added the Category options like AllowBluetoothA2DP for fixing some other issues. Since then Bluetooth to Earpiece switching is not happening. But same code is working fine in iOS 14 and below.
Please provide solution to fix this issue or share cause of this issue may help us to investigate further.
Code: Xamarin iOS
AVAudioSessionCategory category = AVAudioSessionCategory.SoloAmbient;
AVAudioSessionCategoryOptions options = 0;
AVAudioSessionPortOverride port = AVAudioSessionPortOverride.None;
NSString mode = AVAudioSession.ModeDefault;
//When VOIP call gets connected m_active will be true
if (m_active) {
mode = AVAudioSession.ModeVoiceChat;
category = AVAudioSessionCategory.PlayAndRecord;
options = AVAudioSessionCategoryOptions.AllowBluetooth;
}
//Setting mode and category
AVAudioSession.SharedInstance().SetMode(mode, out err);
AVAudioSession.SharedInstance().SetCategory(category, options | AVAudioSessionCategoryOptions.DuckOthers | AVAudioSessionCategoryOptions.AllowBluetoothA2DP);
AVAudioSession.SharedInstance().OverrideOutputAudioPort(port, out err);