I have the most standard/out of the box code for calling the delegate function in UIImagePicker:
import Foundation import UIKit //import UIKit.UIImage
class FirstViewController:
UIViewController
, UIImagePickerControllerDelegate
{
let imagePicker = UIImagePickerController()
@IBOutlet weak var bigImageView: UIImageView!
var newlyPickedImage: UIImage?
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = Color.offWhiteLight
let singleTap = UITapGestureRecognizer(target: self, action: #selector(onTapImageView))
self.view.isUserInteractionEnabled = true
self.view.addGestureRecognizer(singleTap)
}
@objc func onTapImageView(){
DispatchQueue.main.async {
self.imagePicker.allowsEditing = true
self.imagePicker.sourceType = .photoLibrary
self.present(self.imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(
_ picker: UIImagePickerController
, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])
{
print("assert enter function") /// not entered
if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
self.bigImageView.image = pickedImage
print("picked image: \(pickedImage)")
}
dismiss(animated: true, completion: nil)
}
}
The issue is that func imagePickerController
is not getting called. This is odd because in a different view the exact code does call func imagePickerController
. I have also tried instantiating a global UIImagePickerController
instance in the Appdelegate and referencing that, the call is still not called.