Photo library

In the info.plist, add:
Privacy - Photo Library Usage Description
(You must search using the capital 'P')

Get the image picker library
Go to build phases
Link binary with libraries, click +
Grab photos.framework for IOS 10

Go view controller.swift
Import Photos

In the class:
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate

Add the following functions:
   @IBAction func getImages(_ sender: Any) {
        let img = UIImagePickerController()
        img.delegate = self
        img.sourceType = UIImagePickerControllerSourceType.photoLibrary
        self.present(img, animated: true, completion: nil)
       
    }
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
        myImageView.image = image
        } else{
            print("Something went wrong")
        }
       
        self.dismiss(animated: true, completion: nil)
    }

}

Comments

Popular posts from this blog

Setting up a playground

Go to another page