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)?

  • Migrating from UIWebView to WKWebView
  • Disable WKWebView for opening links to redirect to apps installed on my iPhone
  • WKWebKit javascript execution when not attached to a view hierarchy
  • Enable Application cache in WKWebView
  • WKWebView and NSURLProtocol not working
  • Xcode 9 GM - WKWebView NSCoding support was broken in previous versions
  • 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 */ 
        } 
    })