I'm in the middle of replacing UIImagePickerController with PHPickerViewController for iOS 14, but I'm having issues displaying the selected photo in the UI using PHPickerViewController. When I select a photo from the Photo Library, the PHPickerViewController dismisses itself without updating the photo in the UI. I've been trying different solutions from various tutorials, but I'm getting the same result each time.
Below is the code I have currently. The code within the DispatchQueue.main.async brackets is what I have been using for UIImagePickerController to display the photo in the UI.
extension EditProfileController: PHPickerViewControllerDelegate {
@available(iOS 14, *)
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
picker.dismiss(animated: true, completion: nil)
for result in results {
result.itemProvider.loadObject(ofClass: UIImage.self) { object, error in
if let image = object as? UIImage {
DispatchQueue.main.async {
self.profileImageView.image = image
self.imageChanged = true
}
}
}
}
}
}