My iOS6 and working code to set bluetooth as an output:
// create and set up the audio session
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
[audioSession setActive: YES error: nil];
// set up for bluetooth microphone input
UInt32 allowBluetoothInput = 1;
OSStatus stat = 0;
stat = AudioSessionSetProperty (
kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
sizeof (allowBluetoothInput),
&allowBluetoothInput
);
The method AudioSessionSetProperty is deprecated since iOS7. Following this thread How Do I Route Audio to Speaker without using AudioSessionSetProperty? you can change the output to AVAudioSessionPortOverrideSpeaker OR AVAudioSessionPortOverrideNone but no Bluetooth options here.
My actual goal is to support bluetooth devices who are not using A2DP but HFP.
So how can I achieve this without using deprecated methods?
To expand on my previous answer and comment:
You would use the AVAudioSession method
with
category
asAVAudioSessionCategoryPlayAndRecord
or
AVAudioSessionCategoryRecord
and
options
asAVAudioSessionCategoryOptionAllowBluetooth
In your reply you say
But according to the Apple docs
I understand that to mean bluetooth HFP, which I presume is what you are after. As regards "forcing", Apple is not too keen on apps forcing/overriding OS control of a user's experience of device behaviour.
It may be that this does not work in practice - I have not been able to test it. Presumably you have, and it fails (you don't indicate in your question). But you are hitting the limits of Apple's documentation on this issue. If you really can't get it to work I would be inclined to go with the deprecated C interface, and be prepared to make changes for iOS8.
By referring to this answer, I came up with the following:
It appears to work the same way as the old property override and redirects both input and output the the hands free device.