Swift Ask for user’s permission to access the photo library

swift access photo library
ios check photo library permission
check camera permission ios swift 4
wkwebview camera access swift
privacy - photo library usage description
use of unresolved identifier 'phphotolibrary'
swift photo gallery tutorial
swift request gallery permission

I'm trying to access the photo library to import a profile image in swift 4.

but i got this error :

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.

I asked for permission in every single way.

I try :

<key>NSPhotoLibraryUsageDescription</key>
    <string>this permission for profile photo only</string>

and the code :

let imagePicker = UIImagePickerController()
 override func viewDidLoad() {
     super.viewDidLoad()
     imagePicker.delegate = self
}
@objc func importUserImage() {
        print("import driver")

        imagePicker.sourceType = .photoLibrary
        imagePicker.allowsEditing = true
        self.present(imagePicker, animated: true)
    }

I try

<key>NSPhotoLibraryAddUsageDescription</key>
    <string>this permission for profile photo only</string>

I even try to do it in code

import UIKit
import Photos
import UserNotifications

class LoginViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        PHPhotoLibrary.requestAuthorization { (status) in
            // cruch here
        }
     }
}

I deleted the app and reinstall it , still crash

Did i forget something? or what i'm doing wrong ?


Try this:

Go to your plist. At the very top, it should say Information Property List have this selected. Then right click and Add Row type Privacy - Photo Library Additions Usage Description then to the right of that there is a value column that needs text entered by you this is what the user will see. I hope this helps!

Swift Ask for user's permission to access the photo library, Try this: Go to your plist. At the very top, it should say Information Property List have this selected. Then right click and Add Row type Privacy  The user must explicitly grant permission for your app to access Photos. Prepare your app for this requirement by providing justification strings. The justification string is a localizable message that you add to your app's Info.plist file to tell the user why your app needs access to the user's photo library.


NSPhotoLibraryUsageDescription should be sufficient if just want to access the user Photo Library and following code of yours will work fine

PHPhotoLibrary.requestAuthorization { (status) in
   // No crash
}

Add following two keys to info.plist if you need read and write permissions

<key>NSPhotoLibraryUsageDescription</key>
<string>this permission for profile photo only</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>this permission for profile photo only</string>

Determine if the access to photo library is set or not , If you are using Swift 3.0 or higher, you can use the following code: // Get NotDetermined: // ask for permissions PHPhotoLibrary. Common problem 1: Some users complain that app doesn't show alert after doing check to see if device settings doesn't allow photo library access", preferredStyle: .alert) let settingsAction  The following is a step-by-step tutorial to create a custom class that will help developers access basic attachments such as Camera Image, Photo Library, Video and File Import using swift 4.


i just add the key NSPhotoLibraryUsageDescription in Project/info/Custom IOS Target Properties . instead of info.plist and now it's working fine

SWIFT: Code block to access iOS Camera, Photo Library, Video , Photos, videos, documents are critical to Noticeboard's users — It's SWIFT: Code block to access iOS Camera, Photo Library, Video, This means that we have to verify if the user has given permission to access their photo or not. notDetermined: // The user has not yet been asked for camera access. Asking for permission The app must ask for permission from the user before accessing the camera. When it does that it will display a message to the user explaining why it needs to use the camera. You can set this message by setting the NSPhotoLibraryUsageDescription key in the Info.plist list of your app.


How To Access The Camera & Photo Library In Swift, To access the camera in Swift, we first must ask the user for permission. Open up your Info.plist file from your Project Navigator. Then right click and click Add  iOS 10, Now Requires User Permission to Access Media Library, Photos, Camera and other Hardware like these. The solution for this is to add their keys into info.plist with a description for user that how we are using their data, I could only find a few keys . NSPhotoLibraryUsageDescription NSMicrophoneUsageDescription NSCameraUsageDescription


How to Create Better User Permission Requests in iOS Apps, There are three keys to optimizing your app's user permission requests. It ties the requests to access the device's photos, camera, and it places both permissions requests on the same overlay using a library called PermissionScope. It doesn't make much sense to ask a user for access to the camera  The iOS 10 SDK provides access to both the camera device and photo library through the UIImagePickerController class. This allows videos and photographs to be taken from within an application and for existing photos and videos to be presented to the user for selection.


[PDF] advanced, asking permissions when the app first runs: we need to access the user's photo library and microphone, and also request permission to transcribe their speech  Asked 5 years, 6 months ago. Active 3 months ago. Viewed 81k times. 96. With the new functionality in iOS 8, if you are using a camera in the app, it will ask for permission to access the camera and then when you try to retake the pic, it asks for permission to access photo library.