I'm currently initializing my AVAudioSession as follows:
NSError *myError = nil;
AVAudioSession* avSession = [AVAudioSession sharedInstance];
[avSession setCategory: AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker|AVAudioSessionCategoryOptionAllowBluetooth error: &myError];
This seems to work fine. If I just start on a device, my output is my speaker. If I plug in a wired headphone, it reroutes audio to the headphone. If I unplug it, it reroutes back to the main speaker. At no time does the audio ever come out of the receiver. This is the correct behavior that I'm looking for.
This also works fine if I use my beats headphones (bluetooth) in lieu of the wired headphones.
The issue arises however if I plug in the beats headphones BEFORE starting the app. The app correctly chooses them and everything is fine however if i then shut off or disconnect the bluetooth headphones, the audio is routed back to the receiver instead of the speaker.
Is there something I'm supposed to be doing so it'll honor my AVAudioSessionCategoryOptionDefaultToSpeaker flag?