I working in swiftui, swift 5 , Xcode Version 13.2.1. I am trying to programmatically request permission for camera usage using the code below but I keep getting the error
Cannot find 'AVCaptureDevice' in scope
here is my code
struct StartZoomVC: UIViewControllerRepresentable {
....
func askPermissionsForCameraFeed() {
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 have researched what could be causing but no answer
CodePudding user response:
AVCaptureDevice
is part of AVFoundation
, so you'll need:
import AVFoundation
Note that you probably want to do request access before checking the status: https://developer.apple.com/documentation/avfoundation/avcapturedevice/1624584-requestaccess