Skip to content

Latest commit

 

History

History
28 lines (24 loc) · 901 Bytes

iOS麦克风权限.md

File metadata and controls

28 lines (24 loc) · 901 Bytes

iOS麦克风权限

- (IBAction)btnClick:(id)sender {
    AVAuthorizationStatus videoAuthStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
    if (videoAuthStatus == AVAuthorizationStatusNotDetermined) {// 未询问用户是否授权
        //第一次询问用户是否进行授权
        [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
            // CALL YOUR METHOD HERE - as this assumes being called only once from user interacting with permission alert!
            if (granted) {
                // Microphone enabled code
            }
            else {
                // Microphone disabled code
            }
        }];
    }
    else if(videoAuthStatus == AVAuthorizationStatusRestricted || videoAuthStatus == AVAuthorizationStatusDenied) {
        //提示未授权
    }
    else {
        //授权成功
    }
}