PhotoPicker discovery error: Error Domain=PlugInKit Code=13
Solution 1
You need to make explicit Objective-C reference: @objc
@objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
image = chosenImage
self.performSegue(withIdentifier: "ShowEditView", sender: self)
dismiss(animated: true, completion: nil)
}
Solution 2
I found this solution. We got this error due to these two reason which is mentioned below.
- First we need to call this method in for authorization
Authorization Code
func checkPermission() {
let photoAuthorizationStatus = PHPhotoLibrary.authorizationStatus() switch photoAuthorizationStatus {
case .authorized: print("Access is granted by user")
case .notDetermined: PHPhotoLibrary.requestAuthorization({
(newStatus) in print("status is \(newStatus)") if newStatus == PHAuthorizationStatus.authorized { / do stuff here */ print("success") }
})
case .restricted: / print("User do not have access to photo album.")
case .denied: / print("User has denied the permission.")
}
}
- Correct way of method Calling of
didFinishPickingMediaWithInfo
Wrong:
private func imagePickerController( picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
}
Right
@objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
}
I hope this solution will help you out to resolve this error.
If it works for you don't forget to mark it's as a correct, so this will help to other to find the correct way.
Solution 3
I found it! It is trying to tell you that you do not have authorization to "photos" You need to include the #import <Photos/Photos.h>
and request authorization for example like this in Objective-C.
Hope this will save you some time. I spent two full days debugging this!
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
switch (status) {
case PHAuthorizationStatusAuthorized:
NSLog(@"PHAuthorizationStatusAuthorized");
break;
case PHAuthorizationStatusDenied:
NSLog(@"PHAuthorizationStatusDenied");
break;
case PHAuthorizationStatusNotDetermined:
NSLog(@"PHAuthorizationStatusNotDetermined");
break;
case PHAuthorizationStatusRestricted:
NSLog(@"PHAuthorizationStatusRestricted");
break;
}
}];
I am sure someone can tell you how to do the same in Swift.
Solution 4
Tried a few of the combination responses without much success.
Using Swift 4, I found that I needed to make sure the following two items were implemented to ensure that the image was selected and placed into the picker (note that the "[discovery] errors encountered while discovering extensions:
Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}"
message still displays in the console, but it does not prevent you from adding an image). Maybe this is a message that results in the picker being dismissed?
1) The delegate for the UIImagePickerController
is (UIImagePickerControllerDelegate & UINavigationControllerDelegate)?
so need to explicitly add the UINavigationControllerDelegate
as one of the protocols:
class ViewController:UIViewController, UIImagePickerControllerDelegate,
UINavigationControllerDelegate { .... }.
2) Make sure that the info.plist has the Privacy - Photo library Usage Description
key and String value set.
Of course, you need to ensure that you create a UIImagePickerController
and set its delegate equal to self
in ViewDidLoad()
:
class ViewController:UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
let imagePickerController = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
imagePickerController.delegate = self
}
...
}
Solution 5
XCODE 10.1 / SWIFT 4.2 :
Add required permissions (others mentioned)
Implement this delegate func:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage { self.imgView.contentMode = .scaleAspectFit self.imgView.image = pickedImage } dismiss(animated: true, completion: nil) }
Related videos on Youtube
![Kreason Naidoo](https://lh4.googleusercontent.com/-hHQs5vSRQVE/AAAAAAAAAAI/AAAAAAAAB5I/vUxxAIssXpM/photo.jpg?sz=256)
Kreason Naidoo
Updated on August 31, 2020Comments
-
Kreason Naidoo almost 4 years
I'm trying to display an image from the photo library in a UIImageView
The full error is:
2017-06-09 21:55:59.063307+0200 firstapp2.0[12873:1120778] PhotoPicker discovery error: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}
My code is included below:
import UIKit class ViewController: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate{ @IBOutlet weak var pic: UIImageView! @IBOutlet weak var text: UILabel! var chosenImage : UIImage! override func viewDidLoad() { super.viewDidLoad() pic.isUserInteractionEnabled = true; } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [AnyHashable: Any]) { var chosenImage = info[UIImagePickerControllerEditedImage] self.pic!.image = chosenImage as! UIImage picker.dismiss(animated: true, completion: nil) } func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { picker.dismiss(animated: true, completion: nil) } @IBAction func tap(_ sender: Any) { self.text.text = "Kreason" let imagePicker = UIImagePickerController() imagePicker.delegate = self imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary imagePicker.allowsEditing = false self.present(imagePicker, animated: true, completion: nil) } }
-
Kreason Naidoo about 7 yearsHi, it throws the error once I've selected an image. (clicked use image) From what I can see the failing is when the imagepicker tries to close. I'm very new to IOS dev so any help would go a long way, thank you :)
-
John about 7 yearsI got the same error. are you using Xcode 9 beta, iOS 11?
-
user2153553 almost 7 yearsThis used to work... and then iOS 11 Beta 4 gave me this error all of sudden. So weird.
-
valeCocoa over 6 yearsI'm getting the same error and my implementation is in obj-c. This error message cannot be related to the type casting of the info dictionary returned in the UIImagePicker delegate method in objective-c:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
the dictionary values are casted as id in obj-c. I've also implemented the authorization request and handling for accessing user's photo library: still getting the error message. I've added in the info.plist file the privacy entry for user's photo library use. -
valeCocoa over 6 yearsI also tried dismissing the image picker in the delegate method by calling dismissViewController on both, the view controller which presented it (which in my case occur to be the also the delegate), and on the UIImagePickerController itself that gets passed to the delegate method. Still getting this error message, and still getting it either an image gets selected or not.
-
valeCocoa over 6 yearsI've also tried to keep a strong reference of the image picker instance, but that approach too was still giving the error. Maybe there is another key to add to the info.plist for aside for "Privacy - Photo Library Usage Description"?
-
shokuroff over 6 yearsI receive current bug however it doesn't prevent me to get image from library and use it later..
-
Nicolas Miari over 5 yearsI tried all of the suggestions in all of the answers combined, to no avail.
-
ForceBru almost 4 yearsSo what does the error message mean? What's a "discovery error"?
-
-
Robert Wohnoutka almost 7 yearsbe sure to include #import <Photos/Photos.h>
-
user3144836 over 6 yearsWorks for me. I had recently updated to Swift 4 and Xcode 9 and this resolved it.
-
mayankk2308 over 6 yearsWorks for me. Required after migrating to Swift 4.0.
-
Kimi Chiu over 6 yearsDoesn't work. This error occurred after I called
dismiss
. -
fi12 over 6 yearsThis didn't fix my problem.
-
Dark Castle over 6 yearsStrange. This worked for me however xcode marks it as a warning and expects a signature of: ` Instance method 'imagePickerController(:didFinishPickingMediaWithInfo:)' nearly matches optional requirement 'imagePickerController(:didFinishPickingMediaWithInfo:)' of protocol 'UIImagePickerControllerDelegate' Make 'imagePickerController(_:didFinishPickingMediaWithInfo:)' private to silence this warning `
-
Biranchi over 6 yearsI am getting the below message in console "Reading from private effective user settings. errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled} " . It didn't solve the issue.
-
agrippa about 6 yearsMy error looked something like this: errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled} And this solved my problem, though I can't speak to if this helps the OP. Thanks :)
-
John Montgomery almost 6 yearsThis suppresses the error messages but doesn't address their cause. It also suppresses other system messages and anything from
NSLog
. -
Nicolas Miari over 5 yearsHmm,
internal
is the default; I wonder what difference it makes to specify it... -
Coder ACJHP over 5 yearsGreat answer, you saved my time 👍🏼
-
Mohamed Lee over 5 yearsWell ...not really...for me it shows this error but the didFinishPickingMediaWithInfo method is not called...so I needed to enable this value in order to see this error
-
Mohamed Lee over 5 yearsi have all this in my project.. still it dosen't work
-
Samet Sazak over 5 yearsTrue way of using imagePickerController func on Swift 4x
-
zeeshan over 5 yearsThis doesn't 'solve' the issue, just makes it invisible. Very bad practice.
-
Nico Neill over 5 yearsIt creates error
Objective-C method 'imagePickerController:didFinishPickingMediaWithInfo:' provided by method 'imagePickerController(_:didFinishPickingMediaWithInfo:)' conflicts with optional requirement method 'imagePickerController(_:didFinishPickingMediaWithInfo:)' in protocol 'UIImagePickerControllerDelegate'
-
Maria Ortega over 5 yearsExactly, this is the way to fix it!
-
Alexey Chekanov about 5 yearspicker.delegate = self — was my case! Thank you.
-
Braden Holt about 5 yearsNoob PSA: PHPhotoLibrary is from Swift's Photos module
-
Prometheos II about 5 years@DarkCastle you need to write the function into a
extension [your class name]
block, outside of the class. -
Prometheos II about 5 yearsThis only disables a lot of alerts and NSLog outputs; it doesn't actively solve the problem (unless it is a bug in xcode in itself).
-
Prometheos II about 5 years@NicoNeill did you add the function into an
extension
block? -
danner.tech about 5 yearsYou just said it disables a lot of alerts correct? Isn't that the purpose?
-
Prometheos II about 5 yearsIt disables the alert, but doesn't fix the problem(s). It depends what you're searching for. shrug
-
A.J. Hernandez about 5 yearsThis is exactly what I needed. Thank you!
-
Arshad Shaik about 5 yearsThanks i missed setting delegate in viewDidLoad()
-
shiv almost 5 yearsThis is the equivalent of hiding your dirt under the rug tbh
-
shiv almost 5 yearsWorked wonderfully! Think this is the correct way to deal with the picker errors in Swift 4.x.
-
Sakthimuthiah over 4 yearsThanks, am struggling for long hours and i have missed "UINavigationControllerDelegate", you saved finally, thanks
-
Daniel Arantes Loverde over 4 yearsGlad to help :)
-
ForceBru almost 4 yearsDoesn't work. The error happens after I call
picker.dismiss(animated: true, completion: nil)