UIImagePickerController Swift 3

Sourece:

let picker = UIImagePickerController()

picker.delegate = self

if source != nil {
self.picker.allowsEditing = true

if source == .library {
self.picker.sourceType = .photoLibrary
self.picker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
self.picker.modalPresentationStyle = .popover
}else{
if UIImagePickerController.isSourceTypeAvailable(.camera) {
self.picker.sourceType = UIImagePickerControllerSourceType.camera
self.picker.cameraCaptureMode = .photo
self.picker.modalPresentationStyle = .fullScreen
}else{
self.manager.ShowAlert(Constants.ErrorTitle, Constants.NoCameraFound, self)
}
}

self.present(self.picker, animated: true, completion: nil)
self.picker.popoverPresentationController?.permittedArrowDirections = .up
}

extension AccountTableViewController : UIImagePickerControllerDelegate, UINavigationControllerDelegate {

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

let chosenImage = info[UIImagePickerControllerEditedImage] as! UIImage //2

let imageData = UIImageJPEGRepresentation(chosenImage, 0.2)
let dataBase64 = imageData?.base64EncodedData(options: .lineLength64Characters)
APIManager.shared.UploadImage(dataBase64!, self)
dismiss(animated:true, completion: nil)
}

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}

}

Image:

UIImagePickerController Swift 3