22

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 ...

  • some people said add @objc
  • some people said add internal
  • some people suggested adding _ and making sure using Any and not AnyObject
  • some people said to use didFinishPickingImageWithInfo (this returns no image for me)
  • some people said dismsss the picker, others said dismiss self, others said dismiss both
  • some said add the 'Privacy... ' to plist (done)
  • added import Photos
  • added prior call to force PHPhotoLibrary.requestAuthorization() { (status) -> Void in ...

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)
}
Saravanan Sachi
  • 2,572
  • 5
  • 33
  • 42
john
  • 505
  • 1
  • 7
  • 15

10 Answers10

16
  1. add the 'Privacy... ' to plist
  2. From Xcode menu open: Product > Scheme > Edit Scheme > On your Environment Variables set OS_ACTIVITY_MODE in the value set disable

see in mc-system-group-container-and-mc-reading-from-public-effective-user-settings-err

Work's fine for me

EDIT

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)
    }
}
  • Can we have an objective-c version too? – Reza.Ab Jan 27 '18 at 00:29
  • 3
    Can you explain what this does or why this works? I'm hesitant to add a setting without understanding the implications. Thanks much, it seems this answer works well for some! (though not all) – woody121 May 02 '18 at 15:17
  • 7
    After a bit of searching, it seems like this disables logging. Hiding the message is not a fix in my book. – Henrik Nov 20 '18 at 17:56
  • Disabling `OS_ACTIVITY_MODE` sounds like pretending a problem doesn't exist and hoping for the best. I would never recommend this – Ky - Feb 05 '21 at 17:53
4

For Swift 4:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    guard let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else {
        return
    }
    ...
}
  • On method parameter, change from [String: Any] to [UIImagePickerController.InfoKey : Any]
  • On the picked image, change from info["UIImagePickerControllerOriginalImage"] to info[UIImagePickerController.InfoKey.originalImage]
CodeBender
  • 35,668
  • 12
  • 125
  • 132
  • This is definitely the one that helped me. The original imagePickerController didFinishPickingImage delegate method was never being called - had to update to the new delegate method. – Misha Stone Jan 18 '19 at 04:06
2

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.

Yuchen
  • 30,852
  • 26
  • 164
  • 234
  • 1
    Wow thanks, this fixed my bug! I only had the NSPhotoLibraryUsageDescription ... weird, it was hard to debug this! – Romy Ilano Apr 22 '18 at 19:54
2

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.

Kai
  • 1,277
  • 2
  • 15
  • 25
2

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

ZUser
  • 59
  • 6
1

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
user339946
  • 5,961
  • 9
  • 52
  • 97
  • Done this, and implemented the protocol otherwise I wouldn't get the selected image. Still getting this error. – valeCocoa Oct 11 '17 at 10:53
  • tried ... imagePicker.delegate = self as UIImagePickerControllerDelegate & UINavigationControllerDelegate .. and still get the error. Was just doing = self. but no difference – john Oct 12 '17 at 03:45
  • Sorry, I still get the log message as well, this solution is actually if you can't receive the delegate method for image selection. I'm assuming the log message is just an xcode bug and will be fixed eventually. – user339946 Oct 12 '17 at 05:13
1

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
        }
    }
}
eemrah
  • 1,603
  • 3
  • 19
  • 37
1

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.

Richard Poutier
  • 207
  • 2
  • 10
0

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
Marcos Reboucas
  • 3,409
  • 1
  • 29
  • 35
0
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

Deviyani Swami
  • 749
  • 8
  • 17