0
votes

In my app I record what the user says and relay it back to them.

I set the category like so to allow for play and record and for bluetooth devices:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error: &error];

I am subscribed to the notification - AVAudioSessionRouteChangeNotification

When the bluetooth device is disconnected and reconnected I can see the routeChangeReason : AVAudioSessionRouteChangeReasonCategoryChange

I can see the port type is BluetoothHFP which is good.

But then there is another notification seconds after with the route change reason as: AVAudioSessionRouteChangeReasonOverride

Then it switches back to the in built ipad mic but the speaker stays with the bluetooth device?

Why does the override happen?

1

1 Answers

0
votes

I was able to solve this by recovering from the override by checking if there is a bluetooth device connected and then setting this as the prefered input:

NSArray *availInputs = [[AVAudioSession sharedInstance] availableInputs];
        int count = [availInputs count];
        for (int i = 0; i < count; i++) {
            AVAudioSessionPortDescription* inPort = [availInputs objectAtIndex:i];
            if([inPort.portType isEqualToString:@"BluetoothHFP"]) {
                NSError *setPreferredErr = nil;
                [[AVAudioSession sharedInstance] setPreferredInput:inPort error:&setPreferredErr];
                if(setPreferredErr)
                    NSLog (@"connectToBlueToothDeviceIfAvailable setPreferredInput:%@", setPreferredErr);
            }
        }