Sjo*_*ors 3 bluetooth avfoundation ios
我的iOS6和工作代码将蓝牙设置为输出:
// 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
);
Run Code Online (Sandbox Code Playgroud)
从iOS7开始,不推荐使用AudioSessionSetProperty方法.遵循此主题如何在不使用AudioSessionSetProperty的情况下将音频路由到扬声器?您可以将输出更改为AVAudioSessionPortOverrideSpeaker或AVAudioSessionPortOverrideNone但此处没有蓝牙选项.
我的实际目标是支持不使用A2DP但使用HFP的蓝牙设备.
那么如何在不使用弃用方法的情况下实现这一目标呢?
扩展我之前的回答和评论:
您将使用AVAudioSession方法
- (BOOL)setCategory:(NSString *)category
withOptions:(AVAudioSessionCategoryOptions)options
error:(NSError **)outError
Run Code Online (Sandbox Code Playgroud)
用category
as
AVAudioSessionCategoryPlayAndRecord
或AVAudioSessionCategoryRecord
而options
作为
AVAudioSessionCategoryOptionAllowBluetooth
在你的回复中你说
这是不一样的,因为这将只允许A2DP蓝牙
但根据Apple的文档
AVAudioSessionCategoryOptionAllowBluetooth
允许蓝牙免提设备显示为可用的输入路由.
我明白这意味着蓝牙HFP,我认为是你所追求的.至于"强制",Apple并不太热衷于强制/重写操作系统控制用户体验设备行为的应用程序.
可能这在实践中不起作用 - 我无法测试它.大概你有,但它失败了(你没有在你的问题中指出).但是你在这个问题上达到了Apple的文档限制.如果你真的无法让它工作,我会倾向于使用已弃用的C接口,并准备对iOS8进行更改.
归档时间: |
|
查看次数: |
4806 次 |
最近记录: |