IOS录音:录音权限

在IOS上录音,需要先获得权限,不然录音只能返回空数据。

获得权限有两步:

1.Info设置

在Xcode->Info->Custom iOS target properties里,添加Privacy-Microphone Usage Description设置,并填写一段描述。IOS录音:录音权限_第1张图片

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");
        }
    }
}

你可能感兴趣的:(iOS开发音视频)