-(int)openAVAudioSessionRecordPermission {
AVAudioSessionRecordPermission permissionStatus = [[AVAudioSession sharedInstance] recordPermission];
if (permissionStatus == AVAudioSessionRecordPermissionUndetermined) {
// 创建一个信号量的初始值
dispatch_semaphore_t signal = dispatch_semaphore_create(0);
__block int speakSessionIdBlock =0;
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
if(granted) {
// block代码中给变量赋值
speakSessionIdBlock = 100;
// 发送信号 下面的代码一定要写在赋值完成的下面
dispatch_semaphore_signal(signal);
} else {
dispatch_semaphore_signal(signal);
}
}];
// 等待执行的方法返回值
dispatch_semaphore_wait(signal, DISPATCH_TIME_FOREVER);
return speakSessionIdBlock;
}
网友评论