UIImagePickerController exception : "Source type must be UIImagePickerControllerSourceTypeCamera"

Viewed 12852

what is wrong with this? I really don't understand some important parts for UIImagePickerController....

here's the source:

     UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;        
imagePickerController.delegate = self;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];

Can't I open the photo library? Any help appreciated!

5 Answers

I had this exact same exception, however I wasn't using an instance of UIImagePickerController control, instead I was showing a web page inside of a UIWebView that had an input w/ HTML Media Access attributes to enable camera access.

The problem is that it seems the UIWebView does not handle the HTML Media Access attributes properly. I noticed that the spec on these attributes changed a few times over time, so while it seemed like valid html and works on safari on the device, it doesn't work on pages rendered using UIWebView.

Bad:

<input type="file" accept="image/*" capture="camera" />

Good:

<input type="file" accept="image/*;capture=camera" />

The exception immediately went away and taking a picture works. This seems to be new to iOS 10 or 11 as it was existing code and didn't blow up in the past.

Related