I think AVAudioSession APIs have evolved quite a bit since iOS7 and often are confusing. My objective is to setup a RemoteIO unit, record audio from microphone and playback samples simultaneously through headphones. If no headphones are present, then do not playback. If Bluetooth microphone is present, then pick it up as preferred one instead of a headset mic or USB mic. If there is a separate headphone present, then playback the samples through it. If the same bluetooth mic also has headset capability, then avoid it to playback the samples as it is going to loopback creating a mess.
What are the right APIs to get this done? Currently I am using the following code but it doesn't do the full job.
AVAudioSession *session = [AVAudioSession sharedInstance];
NSUInteger bluetoothOpt = AVAudioSessionCategoryOptionAllowBluetooth;
if (![session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:bluetoothOpt | AVAudioSessionCategoryOptionMixWithOthers error:nil]) {
NSLog(@"Could not set audio session category");
}
Should I use AVAudioSessionCategoryMultiRoute instead? How do I select preferred input and output? Everything on iOS 11 as I see APIs are behaving differently on it.