如何在iOS中查找蓝牙音频设备
答案:2 悬赏:80
解决时间 2021-12-21 00:51
- 提问者网友:晨熙污妖王
- 2021-12-20 08:48
如何在iOS中查找蓝牙音频设备
最佳答案
- 二级知识专家网友:ー何必说爱
- 2021-12-20 09:32
首先,您需要配置您的应用程序允许蓝牙连接,支持音频的音频会话。你能做到的例如,您的应用程序代表-(BOOL) 应用程序:(UIApplication *) 应用程序 didFinishLaunchingWithOptions:(NSDictionary *) launchOptions 方法。请确保您 AVFoundation 框架联系起来,并将使用它的头中导入。
#import // place in .h
[self prepareAudioSession];// called from application didFinishLaunchingWithOptions
- (BOOL)prepareAudioSession {
// deactivate session
BOOL success = [[AVAudioSession sharedInstance] setActive:NO error: nil];
if (!success) {
NSLog(@"deactivationError");
}
// set audio session category AVAudioSessionCategoryPlayAndRecord options AVAudioSessionCategoryOptionAllowBluetooth
success = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
if (!success) {
NSLog(@"setCategoryError");
}
// activate audio session
success = [[AVAudioSession sharedInstance] setActive:YES error: nil];
if (!success) {
NSLog(@"activationError");
}
return success;
}
#import // place in .h
[self prepareAudioSession];// called from application didFinishLaunchingWithOptions
- (BOOL)prepareAudioSession {
// deactivate session
BOOL success = [[AVAudioSession sharedInstance] setActive:NO error: nil];
if (!success) {
NSLog(@"deactivationError");
}
// set audio session category AVAudioSessionCategoryPlayAndRecord options AVAudioSessionCategoryOptionAllowBluetooth
success = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
if (!success) {
NSLog(@"setCategoryError");
}
// activate audio session
success = [[AVAudioSession sharedInstance] setActive:YES error: nil];
if (!success) {
NSLog(@"activationError");
}
return success;
}
全部回答
- 1楼网友:如果这是命
- 2021-12-20 10:33
能
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯