0

I need to prompt user for microphone permissions, if my app does not have it. It is a view controller that record video using AVCaptureSession. I have found how to do it using AvAudioSession:

How to detect microphone input permission refused in iOS 7

But is it possible to do the same with AvCaptureSession in order to record video?

  1. Detect if user has granted microphone permissions
  2. If not, ask again for permissions

Thanks

Community
  • 1
  • 1
roof
  • 450
  • 3
  • 13
  • 20

1 Answers1

2

Here is an example code from 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
}

i would recomend you try to change the media type to '.audio' for microphone usage like this:

AVCaptureDevice.authorizationStatus(for: AVMediaType.audio)

Source: https://developer.apple.com/documentation/avfoundation/...

Coskun Caner
  • 101
  • 7