PhotoPicker discovery error: Error Domain=PlugInKit Code=13 PhotoPicker discovery error: Error Domain=PlugInKit Code=13 swift swift

PhotoPicker discovery error: Error Domain=PlugInKit Code=13


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)}


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.


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.