问题
I'm trying to use UIImagePickerController. It used to work fine but suddenly stopped working.
Currently, I have inconsistent results(it sometimes works but sometimes doesn't). Here are methods related to UIIMagePickerController.
What is wrong?
@IBAction func uploadImageTapped(_ sender: UIButton) {
let pickerView = UIImagePickerController()
// Set cameraroll sor chooseing a photo
// choose '.camera' if you want to take the picture
pickerView.delegate = self
pickerView.sourceType = .photoLibrary
self.present(pickerView, animated: true, completion: nil)
}
.
.
.
extension RetailerProfileViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
// method that will be called when user choose the pic
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
// get the info of photo
let image = info[.originalImage] as! UIImage
// show it
storeImage.image = image
// dismiss the photo library
self.dismiss(animated: true)
}
}
回答1:
Try to make UIImagePickerController a class variable and to create it only once. Don't initialise it on every tap will hopefully resolve your issue use this code
picker.dismiss(animated: true, completion: nil) // dismiss picker
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
storeImage.image = image
})
回答2:
You can check here. https://stackoverflow.com/a/60397039/12494594
I checked the details, and there are no issues in your implementation. I also checked the apple's official sample here. https://developer.apple.com/documentation/uikit/uiimagepickercontroller/customizing_an_image_picker_controller Same result!
Finally, this is an issue related to iOS Simulators(version 11.3.1). I just want you guys not wasting time on this. Move ahead.
Thanks.
来源:https://stackoverflow.com/questions/60175009/keep-getting-an-error-uiimagepickercontroller-extension-discovery-failed-with