1

I am having trouble with UIImagePickerController. I want to be able to open the photo library and select an image, when I do I get the following error

[discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}`

I assumed this was probably a permissions error since I mistakenly hadn't added a row in my plist for photo access so I added the entry for photo library access:

Privacy - Photo library Usage Description with the type string and value set to photo use

and still I get no prompt for permission to access photos when I try and access them.

To minimise anything else causing problems I have made a new project it simply has a single view controller and the above entry in the plist, below shows the only code in this class

class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate
{
    var mImagePicker:UIImagePickerController?

    override func viewDidLoad()
    {
        super.viewDidLoad()
       // Do any additional setup after loading the view, typically from a nib.
    }

    @IBAction func tapped(_ sender: Any)
    {
        // Pick an image from the photo library
        if UIImagePickerController.isSourceTypeAvailable(.photoLibrary)
        {
            mImagePicker = UIImagePickerController()
            mImagePicker!.delegate = self
            mImagePicker!.sourceType = .photoLibrary;
            mImagePicker!.allowsEditing = false
            self.present(mImagePicker!, animated: true, completion: nil)
        }
    }
}

when I tap the button I see no prompt for permission, the photo library simply appears and when I select a photo I get the error shown above? is there something I'm missing here?

Im running iOS 12 on an iPhone X and Xcode 10.0 on the latest version of the Mojave beta

AngryDuck
  • 4,358
  • 13
  • 57
  • 91
  • as a note if I add the plist entry for camera access and open up the camera using UIImagePickerController it asks for camera permission, which is why I'm so confused by this not asking for photo permission – AngryDuck Sep 21 '18 at 15:40
  • Have you implemented the delegate functions of uiimagepickercontroller? – shivi_shub Sep 21 '18 at 15:59
  • Yes I have, I have the didFinishPickingMediaWithInfo function, however after manually requesting permission the problem actually appears to be on the dismissal of the UIImagePickerController in that function, however it should still be just requesting permission on its own as the camera does so I guess this question still stands, but the error itself is from dismissing the view – AngryDuck Sep 21 '18 at 16:02
  • Please add the code of delegates in your question. And you can use didfailpickingmedia delegate and try to print the error. – shivi_shub Sep 21 '18 at 16:04
  • @AngryDuck did you add an item the `Required device capabilities` of `video-camera`? I think that the both that and the `Privacy...` need to be added. I'm not sure that it will solve the issue though. – Rhetorical Sep 21 '18 at 16:55
  • I get this *warning* or *message* every time, and it isn't an *error*. To squelch it, add `OS_ACTIVITY_MODE` "disabled" to your environment variables. That said, you may have something else going on - is everything behaving correctly? Are you able to (a) access the photo library and (b) select images? If so, don't be concerned. –  Sep 21 '18 at 19:21

1 Answers1

5

You don't actually need permission if you're just accessing photos using UIImagePickerController from iOS 11. Permission is required when you use AVFoundation or Photos framework.

In my experience, iOS logs those errors that we can ignore sometimes, and I think you can ignore the error messages this time.

sj-r
  • 561
  • 2
  • 10
  • Are you... sure about this? I needed to add this privacy measure in order to use it. Without it, IIRC, one can *use* the image picker but ultimately won't actually *get* the image picked. (Please note, I could be wrong.) –  Sep 21 '18 at 19:24
  • 2
    Yes 100%. Just try it yourself. It doesn't require more than 20 lines of code for you to test it. If you're using `imagePickerController.sourceType = .camera`, you need camera usage permission, but as long as you only use `.photoLibrary` or `.savedPhotosAlbum` you don't need ANY permission. – sj-r Sep 22 '18 at 03:12
  • Thanks :), I think the error I'm seeing must be something to do with how I'm dismissing it after selecting a photo but you seem to be correct permission doesn't matter for just viewing photos – AngryDuck Sep 24 '18 at 08:01