Request Permission for Camera and Library in iOS 10 – Info.plist

I have implemented a WKWebView in an app.
there’s a file input in the shown web page where it should import an image from photos.
Whenever i press on that input and select either “Take Photo” or “Photo Library” the app suddenly crash, which I believe is because the app is missing the permission to either take a photo or import from library.

How do I push a permission request when the user select one of the mentioned methods (Take Photo or Photo Library)?

  • PhoneGap Notification.Alert not working
  • When an instance of a class is initialized, what is the sequence?
  • trying to add done button to Numeric keyboard
  • CocoaAsyncSocket and reading data from a socket
  • Images can't contain alpha channels or transparencies
  • Navigation bar overlapped by status bar
  • I use Swift 3.0 with WKWebView.

    4 Solutions Collect From Internet About “Request Permission for Camera and Library in iOS 10 – Info.plist”

    You have to add the below permission in Info.plist. Permission in Info.plist

    Camera :

    Key       :  Privacy - Camera Usage Description   
    Value     :  $(PRODUCT_NAME) camera use
    

    Photo :

    Key       :  Privacy - Photo Library Usage Description    
    Value     :  $(PRODUCT_NAME) photo use
    

    You can also request for access programmatically, which I prefer because in most cases you need to know if you took the access or not.

        //Camera
        AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo) { response in
            if response {
                //access granted
            } else {
    
            }
        }
    
        //Photos
        let photos = PHPhotoLibrary.authorizationStatus()
        if photos == .notDetermined {
            PHPhotoLibrary.requestAuthorization({status in
                if status == .authorized{
                    ...
                } else {}
            })
        }
    

    You do not share code so I cannot be sure if this would be useful for you, but general speaking use it as a best practice. Btw the code is swift 3.0

    File: Info.plist

    For Camera:

    <key>NSCameraUsageDescription</key>
    <string>You can take photos to document your job.</string>
    

    For Photo Library, you will want this one to allow app user to browse the photo library.

    <key>NSPhotoLibraryUsageDescription</key>
    <string>You can select photos to attach to reports.</string>
    

    To ask permission for the photo app you need to add this code (Swift 3):

    PHPhotoLibrary.requestAuthorization({ 
           (newStatus) in 
             if newStatus ==  PHAuthorizationStatus.authorized { 
              /* do stuff here */ 
        } 
    })