Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 630 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PhotoPicker discovery error: Error Domain=PlugInKit Code=13

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




Reply

#2
In my case as swift allocation memory management seems to be optimised and fixed by Apple Team.
My code was perfectly working till a swift update and I found my "mistake" was that I wasn't retaining the picker but It has been working for ages without the retention so here a full ready to work solution.

// Add Privacy - Photo Library Usage Description to your info.plist
<key>NSPhotoLibraryUsageDescription</key>
<string>APPNAME need to access your pictures to violate your privacy :P</string>

And

import Photos
class MyImageSelector: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate {

var picker = UIImagePickerController()
// Make sure to retain this picker var until the picker returned

func checkPermission() {
let call = self.presentAuthorized

let photoAuthorizationStatus = PHPhotoLibrary.authorizationStatus()
switch photoAuthorizationStatus {
case .authorized:
print("Access is granted by user")
showPicker()
case .notDetermined:
PHPhotoLibrary.requestAuthorization({ newStatus in
print("status is \(newStatus)")
if newStatus == PHAuthorizationStatus.authorized {
/* do stuff here */
print("success")
showPicker()
}
})
case .restricted:
print("User do not have access to photo album.")
case .denied:
print("User has denied the permission.")
}

}

func showPicker() {
picker = UIImagePickerController()
picker.allowsEditing = true
picker.sourceType = .photoLibrary
picker.delegate = self //Don't forget this line!
self.present(picker, animated: true, completion: nil)
}

@objc public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// DO something with picture
}

@objc public func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
// User cancelled the pick
}
}
Reply

#3
Try not to make UIImagePickerController inside method but to make
it as a class variable and to create it only once.

I had the same issue as you when I forgot to set a delegate to UIImagePickerController
Reply

#4
Swift 5 and Above:

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
}



func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let image = info[.editedImage] as? UIImage else { return }
dismiss(animated: true)
chosenImage = image
**pic.image = chosenImage**

}

@IBAction func tap(_ sender: Any) {
self.text.text = "Kreason"
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
//imagePicker.dataSource = self
imagePicker.allowsEditing = false
self.present(imagePicker, animated: true)

}
}

Reply

#5
This "Error Domain=PlugInKit Code=13" error has confounded a lot of people even though it seems to be a harmless apple debug message. I was having trouble getting the image I picked to set in my UI and thought that that error was the problem however it was something a bit more subtle.

I have my image picker controller in a file separate from the view controller that's presenting it.

**MyViewController.swift**

class MyViewController: UIViewController {
@IBOutlet weak var profileImage: UIImageView!

...
}

extension MyViewController: ImagePickerDelegate {
func didSelect(image: UIImage?) {
self.profileImage.image = image
}
}


**ImagePicker.swift**

open class ImagePicker: NSObject {
...
private func pickerController(_ controller: UIImagePickerController, didSelect image: UIImage?) {
controller.dismiss(animated: true, completion: {self.delegate?.didSelect(image: image)}
)
}
}

Most of the tutorials and answers have the completion set to nil. However if you set the completion to nil and call the delegate's didSelect method separately, the method gets called but the image doesn't set so make sure to use dismiss' completion.

And again, I know this answer might not be directly related to the original question but I have a feeling a lot of people are coming here for this issue and the given solutions aren't helping. The reason is that most of the people giving answers have their image picker controller in the same class as their main view controller and thus not needing to use a completion.
Reply

#6

Use didFinishPickingMediaWithInfo

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
self.dismiss(animated: true, completion: nil)
var chosenImage = info[UIImagePickerController.InfoKey.editedImage] as! UIImage
userProfileImage.image = chosenImage

uploadImage(chosenImage)
}
Reply

#7
This fixes the issue in Swift 4:

Change the code below

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {}

to this:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {}


Swift 4.2 update:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]){}
Reply

#8
Fixed it by setting 1 second delay when setting image.

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {

picker.dismiss(animated: false, completion: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
self.discussionImage.image = image
})
}
}
Reply

#9
Finding the fix for this problem took me forever. It looks like the problem is that the function imagePickerController of the UIImagePickerControllerDelegate cannot be found. If you have set the delegate correctly and it stopped working after upgrading to Swift 4, the problem is probably that you didn't make it accessible to Objective-C by using @objc which is required since Swift 4.

It has to be:

> @objc func imagePickerController(...

instead of

func imagePickerController(...

Reply

#10
Had this same issue on **Swift 4.2** and **Xcode 10.0**. Although the image picker was working correctly Xcode showed this error on console. To get rid of this:

- On Xcode menu Product > Scheme > Edit Scheme
- Select 'Run' tab, then 'Arguments'
- On 'Environment Variables' section add a variable with Name **OS_ACTIVITY_MODE** and Value **disable**

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through