Search code examples
iosuiimagepickercontroller

Not showing alert even when I add Camera Usage Description / Photo Library Usage Description


I have camera/ photo library in my app, so I add request permission in plist. However, after running app, it does not even pop up alert. Just access to pick photo / camera. Is there anything I miss to add?

Thanks!

enter image description here

enter image description here


Solution

  • Requesting Authorization for Media Capture on iOS: https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_ios

    Configure Your App's Info.plist File:

    If your app uses device cameras, include the 'NSCameraUsageDescription' key in your app’s Info.plist file.

    Verify and Request Authorization for Capture:

       override func viewDidLoad() {
           super.viewDidLoad()
             switch AVCaptureDevice.authorizationStatus(for: .video) {
              case .authorized:  // The user has previously granted access to the camera.
                  .....
    
              case .notDetermined: // The user has not yet been asked for camera access.
                   AVCaptureDevice.requestAccess(for: .video) { granted in
                    if granted {
                        .....
                    }
            }
    
             case .denied: // The user has previously denied access.
                 return
             case .restricted: // The user can't grant access due to restrictions.
               return
           }
     }