PhotoPicker discovery error: Error Domain=PlugInKit Code=13

73,658

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.

  1. 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.")
  }
}
  1. 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 :

  1. Add required permissions (others mentioned)

  2. 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)
    }
    
Share:
73,658

Related videos on Youtube

Kreason Naidoo
Author by

Kreason Naidoo

Updated on August 31, 2020

Comments

  • Kreason Naidoo
    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
      Kreason Naidoo about 7 years
      Hi, 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
      John about 7 years
      I got the same error. are you using Xcode 9 beta, iOS 11?
    • user2153553
      user2153553 almost 7 years
      This used to work... and then iOS 11 Beta 4 gave me this error all of sudden. So weird.
    • valeCocoa
      valeCocoa over 6 years
      I'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> *)infothe 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
      valeCocoa over 6 years
      I 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
      valeCocoa over 6 years
      I'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
      shokuroff over 6 years
      I receive current bug however it doesn't prevent me to get image from library and use it later..
    • Nicolas Miari
      Nicolas Miari over 5 years
      I tried all of the suggestions in all of the answers combined, to no avail.
    • ForceBru
      ForceBru almost 4 years
      So what does the error message mean? What's a "discovery error"?
  • Robert Wohnoutka
    Robert Wohnoutka almost 7 years
    be sure to include #import <Photos/Photos.h>
  • user3144836
    user3144836 over 6 years
    Works for me. I had recently updated to Swift 4 and Xcode 9 and this resolved it.
  • mayankk2308
    mayankk2308 over 6 years
    Works for me. Required after migrating to Swift 4.0.
  • Kimi Chiu
    Kimi Chiu over 6 years
    Doesn't work. This error occurred after I called dismiss.
  • fi12
    fi12 over 6 years
    This didn't fix my problem.
  • Dark Castle
    Dark Castle over 6 years
    Strange. 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
    Biranchi over 6 years
    I 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
    agrippa about 6 years
    My 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
    John Montgomery almost 6 years
    This suppresses the error messages but doesn't address their cause. It also suppresses other system messages and anything from NSLog.
  • Nicolas Miari
    Nicolas Miari over 5 years
    Hmm, internal is the default; I wonder what difference it makes to specify it...
  • Coder ACJHP
    Coder ACJHP over 5 years
    Great answer, you saved my time 👍🏼
  • Mohamed Lee
    Mohamed Lee over 5 years
    Well ...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
    Mohamed Lee over 5 years
    i have all this in my project.. still it dosen't work
  • Samet Sazak
    Samet Sazak over 5 years
    True way of using imagePickerController func on Swift 4x
  • zeeshan
    zeeshan over 5 years
    This doesn't 'solve' the issue, just makes it invisible. Very bad practice.
  • Nico Neill
    Nico Neill over 5 years
    It creates error Objective-C method 'imagePickerController:didFinishPickingMediaWithInfo:' provided by method 'imagePickerController(_:didFinishPickingMediaWithInfo:)' conflicts with optional requirement method 'imagePickerController(_:didFinishPickingMediaWithInfo:)' in protocol 'UIImagePickerControllerDelegate'
  • Maria Ortega
    Maria Ortega over 5 years
    Exactly, this is the way to fix it!
  • Alexey Chekanov
    Alexey Chekanov about 5 years
    picker.delegate = self — was my case! Thank you.
  • Braden Holt
    Braden Holt about 5 years
    Noob PSA: PHPhotoLibrary is from Swift's Photos module
  • Prometheos II
    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
    Prometheos II about 5 years
    This 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
    Prometheos II about 5 years
    @NicoNeill did you add the function into an extension block?
  • danner.tech
    danner.tech about 5 years
    You just said it disables a lot of alerts correct? Isn't that the purpose?
  • Prometheos II
    Prometheos II about 5 years
    It disables the alert, but doesn't fix the problem(s). It depends what you're searching for. shrug
  • A.J. Hernandez
    A.J. Hernandez about 5 years
    This is exactly what I needed. Thank you!
  • Arshad Shaik
    Arshad Shaik about 5 years
    Thanks i missed setting delegate in viewDidLoad()
  • shiv
    shiv almost 5 years
    This is the equivalent of hiding your dirt under the rug tbh
  • shiv
    shiv almost 5 years
    Worked wonderfully! Think this is the correct way to deal with the picker errors in Swift 4.x.
  • Sakthimuthiah
    Sakthimuthiah over 4 years
    Thanks, am struggling for long hours and i have missed "UINavigationControllerDelegate", you saved finally, thanks
  • Daniel Arantes Loverde
    Daniel Arantes Loverde over 4 years
    Glad to help :)
  • ForceBru
    ForceBru almost 4 years
    Doesn't work. The error happens after I call picker.dismiss(animated: true, completion: nil)