views:

813

answers:

4

Hi there,

I have an iPhone app that calls upon the UIImagePickerController to offer folks a choice between selecting images via the camera or via their photo library on the phone. The problem is that sometimes, (Can't always get it to replicate.), the editingInfo dictionary object that is supposed to be returned by didFinishPickingImage delegate message, comes back blank or (null). Has anyone else seen this before?

I am implementing the UIImagePickerControllerDelegate in my .h file and I am correctly implementing the two delegate methods: didFinishPickingImage and imagePickerControllerDidCancel.

Any help would be greatly appreciated. Thank you in advance!

Here is my code...

my .h file:

@interface AddPhotoController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
  IBOutlet UIImageView *imageView;
  IBOutlet UIButton *snapNewPictureButton;
  IBOutlet UIButton *selectFromPhotoLibraryButton;
}
@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) UIButton *snapNewPictureButton;
@property (nonatomic, retain) UIButton * selectFromPhotoLibraryButton;

my .m file:

@implementation AddPhotoController
@synthesize imageView, snapNewPictureButton, selectFromPhotoLibraryButton;

- (IBAction)getCameraPicture:(id)sender 
{

  UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  picker.delegate = self;
  picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  picker.allowsImageEditing = YES;

[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo 
{
NSLog(@"Image Meta Info.: %@",editingInfo);

UIImage *selectedImage = image;
imageView.image = selectedImage;
self._havePictureData = YES;
[self.useThisPhotoButton setEnabled:YES];

[picker dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{
  [picker dismissModalViewControllerAnimated:YES];
}
+1  A: 

I solved the problem. I'm posting my answer here in the hopes it helps someone else in a similar situation:

1. Deprecated Method

The UIImagePickerController method:

– imagePickerController:didFinishPickingImage:editingInfo:

is deprecated in v3.0 of the iPhone OS. So even though I built the app using the SDK v2.2.1, because the app will be running on 3.0 devices, I needed to use the new and improved method:

- imagePickerController:didFinishPickingMediaWithInfo:editingInfo

2. Dismissing the ModalView

The first thing you must do after you have selected a picture from the library or taken a picture with the built-in camera, is to dismiss the picker's modal view window. After that, you can perform any image processing routines. Here is what my final code looks like for that method:

- (void) imagePickerController:(UIImagePickerController *)thePicker didFinishPickingMediaWithInfo:(NSDictionary *)imageInfo 
{
  [thePicker dismissModalViewControllerAnimated:YES];
  UIImage *img = [imageInfo objectForKey:@"UIImagePickerControllerEditedImage"];
  previewImage.image = nil;
  self.previewImage.image = img;

  NSData *imageData = UIImagePNGRepresentation(img);
  if ([imageData length] > 0) {

    [self archivePictureData:imageData];
    self._havePictureData = YES;

    [self.useThisPhotoButton setEnabled:YES];   
  }

}

I hope this helps someone who needs it.

Thanks,

L.

Leachy Peachy
A: 

no still not helping. i have it the same as you but for some reason the program never enters the didFinishPicking method after the picture is seleceted...

dude
A: 

I have the same problem with my UIImagePickerController only when I chose to allow editing. I try allowsEditing and allowsImageEditing but twice seems to dysfunction.

It's very strange, I see it running fine for couple of days, and suddenly there is something wrong.

you can see a screenshot here : http://intraweb.progexis.fr/images/IMG_0225.PNG

I can chose a photo in my library and after, the edit screen is black.

Someone who can help me ?

thank you.

Luc

lkuulu
A: 

I GOT IT !

I don't know why, but I had comment a line in my appDelegate : "[window makeKeyAndVisible]"

I just decomment It and build again. So the Edit function of ImagePicker run now.

I hope this help.

Lkuulu

lkuulu