共计 831 个字符,预计需要花费 3 分钟才能阅读完成。
在 IOS 上录音,须要先取得权限,不然录音只能返回空数据。
取得权限有两步:
1.Info 设置
在 Xcode->Info->Custom iOS target properties 里,增加 Privacy-Microphone Usage Description
设置,并填写一段形容。
2. 代码中动静申请
//recordPermission 获取以后的权限状况
//requestRecordPermission 申请权限
-(void)checkRecordPermission{AVAudioSession* session = [AVAudioSession sharedInstance];
AVAudioSessionRecordPermission recordPermission = [session recordPermission];
if(recordPermission == AVAudioSessionRecordPermissionUndetermined)
{NSLog(@"record permission:%d", recordPermission);
if([session respondsToSelector:@selector( requestRecordPermission:)])
{[session requestRecordPermission:^(BOOL granted) {if( granted)
{NSLog(@"get record permission");
}
else{NSLog(@"not permit record");
}
}];
}
}
else{if( recordPermission == AVAudioSessionRecordPermissionGranted)
{NSLog(@"already get record permission");
}
else{NSLog(@"already denied record permission ,please set in settings");
}
}
}
正文完