【问题标题】:Prompt user for microphone permissions using AVCaptureSession使用 AVCaptureSession 提示用户提供麦克风权限
【发布时间】:2014-03-09 14:17:23
【问题描述】:

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

How to detect microphone input permission refused in iOS 7

但是是否可以对 AvCaptureSession 执行相同的操作来录制视频?

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

谢谢

【问题讨论】:

  • 微权限 == 麦克风权限,对吧?
  • 是的,我已经编辑了我的答案。

标签: objective-c ios7


【解决方案1】:

这是来自 Apple 的示例代码

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/...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-18
    • 2015-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多