In my application, if the iPhone is connected to a Bluetooth headset, play the sound using Bluetooth. Else use the default speaker.
Here is my code
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil]; [[AVAudioSession sharedInstance] setMode:AVAudioSessionModeVoiceChat error:nil]; [[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:nil]; [[AVAudioSession sharedInstance] setActive:YES error:nil];
However, when I tried to use the category setCategory: AVAudioSessionCategoryPlayAndRecord. The route to the Bluetooth device stops working. I do not know why. Since, by right, the bluetooth option should only work for the Record or PlayAndRecord category ...
/ * valid only with AVAudioSessionCategoryRecord and AVAudioSessionCategoryPlayAndRecord * /
Addendum: Can I use bluetooth to output ONLY (the input still uses the default microphone from the phone)?
UPDATE
I changed the order by first calling setMode and then setCategory. It works for the first time when you start the application (call). When I tried to do the same thing again, currentRoute still gave me output = Bluetooth, but the actual output will return to the front speaker of the phone by default.
ios objective-c iphone ios7 bluetooth
xialin
source share