didFinishPickingMediaWithInfo return nil photo

I know this is many months later, but I struggled with this for hours, and found this same question all over this site and iphonedevsdk.com, but never with a working answer.

To summarize, if the image was picked from the camera roll/photo library it worked fine, but if the image was a new photo take with the camera it never worked. Well, here’s how to make it work for both:

You have to dismiss and release the UIImagePickerController before you try to do anything with the info dictionary. To be super-clear:

This DOES NOT work:

- (void)imagePickerController:(UIImagePickerController *)picker 
                      didFinishPickingMediaWithInfo:(NSDictionary *)info {

          // No good with the edited image (if you allowed editing)
  myUIImageView.image = [info objectForKey:UIImagePickerControllerEditedImage];
          // AND no good with the original image
  myUIImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
          // AND no doing some other kind of assignment
  UIImage *myImage = [info objectForKey:UIImagePickerControllerEditedImage];

  [picker dismissModalViewControllerAnimated:YES];
  [picker release];
}

In all of those cases the image will be nil.

However, via the magic of releasing the UIImagePickerController first…

This DOES work:

- (void)imagePickerController:(UIImagePickerController *)picker 
                      didFinishPickingMediaWithInfo:(NSDictionary *)info {

  [picker dismissModalViewControllerAnimated:YES];
  [picker release];

          // Edited image works great (if you allowed editing)
  myUIImageView.image = [info objectForKey:UIImagePickerControllerEditedImage];
          // AND the original image works great
  myUIImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
          // AND do whatever you want with it, (NSDictionary *)info is fine now
  UIImage *myImage = [info objectForKey:UIImagePickerControllerEditedImage];
}

Crazy simple, but that’s all there is to it.

Leave a Comment