Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerController not asking for permission

I have implemented the following code in an app to allow the user to add an image to the app. However the user is never asked for permission to access photo's. What am I missing here?

in my info.plist I have set: Privacy - Photo Library Usage Description = Please provide access to your photo library

The bundle identifier is: $(PRODUCT_BUNDLE_IDENTIFIER)

import UIKit

class NewPostXIB: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet weak var image: UIImageView!

let imagePicker = UIImagePickerController()

override func viewDidLoad() {
    super.viewDidLoad()
    imagePicker.delegate = self
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    super.touchesBegan(touches, with: event)
    self.view.endEditing(true)
}

@IBAction func closeButton(_ sender: Any) {
    dismiss(animated: false, completion: nil)
}

@IBAction func addImageButton(_ sender: Any) {
    if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
        imagePicker.allowsEditing = true
        imagePicker.sourceType = .photoLibrary
        present(imagePicker, animated: true, completion: nil)
        }
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    if let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
        image.contentMode = .scaleAspectFill
        image.image = pickedImage
    }
    dismiss(animated: false, completion: nil)
}

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    dismiss(animated: true, completion: nil)
}
like image 728
scottc00 Avatar asked Feb 16 '18 11:02

scottc00


1 Answers

According to apple documentation

Note

When using the UIImagePickerController to bring up the user's photo library, your app doesn't need to request permission explicitly.

Photos automatically prompts the user to request authorization when needed.

like image 162
Amir Riyadh Avatar answered Oct 13 '22 01:10

Amir Riyadh