//录音之前,先调用下面的语句,询问用户是否可以访问他的 隐私设备麦克风
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted)
{}];
if ([[[AVAudioSession sharedInstance] category] isEqualToString:AVAudioSessionCategoryPlayback])
{
//切换为听筒播放
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[self showTipInfo:@"切换为听筒模式"];
}
else
{
//切换为扬声器播放
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[self showTipInfo:@"切换为扬声器模式"];
}
时间: 2025-01-09 04:26:49