使用AVCaptureSession提示用户输入麦克风权限

时间:2014-03-09 14:17:24

标签: objective-c ios7

如果我的应用没有,我需要提示用户输入麦克风权限。它是一个使用AVCaptureSession录制视频的视图控制器。我已经找到了如何使用AvAudioSession:

How to detect microphone input permission refused in iOS 7

但是,为了录制视频,是否可以使用AvCaptureSession执行相同操作?

  1. 检测用户是否已授予麦克风权限
  2. 如果没有,请再次询问权限
  3. 由于

1 个答案:

答案 0 :(得分:2)

这是苹果公司的示例代码

switch AVCaptureDevice.authorizationStatus(for: .video) {
    case .authorized: // The user has previously granted access to the camera.
        self.setupCaptureSession()

    case .notDetermined: // The user has not yet been asked for camera access.
        AVCaptureDevice.requestAccess(for: .video) { granted in
            if granted {
                self.setupCaptureSession()
            }
        }

    case .denied: // The user has previously denied access.
        return

    case .restricted: // The user can't grant access due to restrictions.
        return
}

我建议您尝试将麦克风使用的媒体类型更改为“ .audio”:

AVCaptureDevice.authorizationStatus(for: AVMediaType.audio)

来源:https://developer.apple.com/documentation/avfoundation/...