Reputation: 535
Similar to
PhotoPicker discovery error: Error Domain=PlugInKit Code=13
and also to
https://forums.developer.apple.com/thread/82105
BUT I have tried all of these suggestions and still get an error in the debug log. Running Swift 4 XCode 9A235
What was suggest at the various places was ...
I DID NOT get this issues in Swift 3 - previous xcode. But with Swift 4, I tried everying I saw suggested and I still get the following error
[discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}
The picker works fine and I DO end up selecting an image from photos, but I get this error message on picker exit (cancel or select), every time...
Any suggestions how to stop the error message? Other than the list of things offered at the other two links (summarized above)
my method
@objc internal func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
imageSelected = nil
if let editedImage = info["UIImagePickerControllerEditedImage"] as? UIImage {
imageSelected = editedImage
} else if let originalImage = info["UIImagePickerControllerOriginalImage"] as? UIImage {
imageSelected = originalImage
}
if imageSelected != nil {
handleSelectedImage() // override in subclass to do something with the returned image
}
picker.dismiss(animated: true, completion: nil) // mess of calling both dismiss to see if it helps - it does not
dismiss(animated: true, completion: nil)
}
Upvotes: 22
Views: 12773
Reputation: 765
var messageImage = UIImage()
@objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
self.dismiss(animated: true, completion: { () -> Void in
})
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
{
messageImage = image
}
print("Image Captured")
}
You need to fetch UIImagePickerController.InfoKey.originalImage
not UIImagePickerController.InfoKey.editedImage
Upvotes: 0
Reputation: 3489
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:
Upvotes: 0
Reputation: 41
For Swift 4:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else {
return
}
...
}
[String: Any]
to [UIImagePickerController.InfoKey : Any]
info["UIImagePickerControllerOriginalImage"]
to info[UIImagePickerController.InfoKey.originalImage]
Upvotes: 4
Reputation: 217
I also had this issue. It's very annoying because the console error comes up but the app is still loading the image. I requested authorization status, added my keys to the .plst, but found none of this to get the job done.
Once I went to Product -> Scheme -> Edit Scheme -> Run then added key: "OS_ACTIVITY_MODE" value: "disable", cleaned and rebuilt...the error went away.
Upvotes: 1
Reputation: 1710
Can you try it out ?
extension YourProfileViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
log.debug("Called imagePickerController function ")
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.dismiss(animated: true) {
self.yourProfileImageView.image = image
}
}
}
Upvotes: 1
Reputation: 67
The user asks: "*Any suggestions how to stop the error message? Other than the list of things offered at the other two links (summarized above)".
I used two steps to eliminate the error message.
Kudos to the person above Antoine Richeux https://stackoverflow.com/users/5767821/antoine-richeux.
I think the Privacy addition to pList may not be necessary, at least in my case
STEP 1. From the Menu bar select: Product > Scheme > Edit Scheme > select Run from the left side list of Build, Run ... Archive Select Arguments from top set of selections on right side - see picture attached. Use the + button under Environment Variables to add a new entry Name: OS_ACTIVITY_MODE Value: disable
This shows where to add the environment variable
STEP 2. Clean the project and rebuild
Upvotes: 2
Reputation: 1477
I had the same issue and tried every solution I could find, but nothing helped. Just asked myself what could happen to the delegate to not being triggered: deallocation of the delegate!
And that was it in my case! When presenting the UIImagePickerController my instance of class ImagePickerController : NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate
which isn't the presenting view controller, will be deallocated directly. Of course the delegate functions can't be executed anymore.
Just put a breakpoint in deinit
(or dealloc
in Objective-C world) and see if your delegate is being deallocated.
Upvotes: 2
Reputation: 33116
It is because your app uses photo library (in this case, using UIImagePickerController
) without asking for user permission. As an example, if I want to show the image picker when the add button was tapped:
@IBAction func addButtonTapped(_ sender: UIBarButtonItem) {
checkPermission {
let picker = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
picker.delegate = self
picker.allowsEditing = false
self.present(picker, animated: true, completion: nil)
}
}
func checkPermission(hanler: @escaping () -> Void) {
let photoAuthorizationStatus = PHPhotoLibrary.authorizationStatus()
switch photoAuthorizationStatus {
case .authorized:
// Access is already granted by user
hanler()
case .notDetermined:
PHPhotoLibrary.requestAuthorization { (newStatus) in
if newStatus == PHAuthorizationStatus.authorized {
// Access is granted by user
hanler()
}
}
default:
print("Error: no access to photo album.")
}
}
In addition, need to add this to your plist as well:
<key>NSPhotoLibraryUsageDescription</key>
<string>So that you can add images for your cloth. </string>
which is the message displayed in the permission dialog.
Upvotes: 2
Reputation: 177
see in mc-system-group-container-and-mc-reading-from-public-effective-user-settings-err
Work's fine for me
if it's can help below my code (working with xcode 9)
if libraryAuthorization == .authorized {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
imagePicker.allowsEditing = false
imagePicker.view.tag = button.tag
self.present(imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let pickerImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
photoContainer.addImageToButton(pickerImage, buttonTag: picker.view.tag)
dismiss(animated: true)
}
}
Upvotes: 16
Reputation: 6119
Make sure you declare that your class implements UINavigationControllerDelegate
.
extension MyViewController: UINavigationControllerDelegate {}
For some reason in Xcode 9.0 it warned me to declare the delegate as such:
imagePicker.delegate = self as? UIImagePickerControllerDelegate & UINavigationControllerDelegate
Upvotes: 1