UIImagePickerControllerDelegate returns empty "editingInfo" Dictionary object

I have an iPhone app that calls on the UIImagePickerController to offer people the choice between choosing images through the camera or through their phone photo library. The problem is that sometimes (it is not always possible to get it for replication.), The editInfo dictionary object that should be returned by the didFinishPickingImage delegate message is returned or (null). Has anyone else seen this before?

I am implementing UIImagePickerControllerDelegate in my .h file and I am implementing two delegate methods correctly: 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];
}

      

+2


source to share


2 answers


I solved the problem. I am posting my answer here in the hope that it will help someone in a similar situation:

1. Deprecated method

UIImagePickerController method:

imagePickerController:didFinishPickingImage:editingInfo:

      

deprecated in version 3.0 of the iPhone operating system. So even if I built the app using SDK v2.2.1, because the app will work on 3.0 devices, I needed to use a new and improved method:

- imagePickerController:didFinishPickingMediaWithInfo:editingInfo

      



2. Firing ModalView

The first thing you need to do after you select an image from the library or take a photo with the built-in camera is to dismiss the modal viewport. Then you can perform any image processing procedures. This is what my final code for this method looks like:

- (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];   
  }

}

      

Hope this helps someone who needs this.

Thank,

L.

+6


source


I GOT IT!

I don't know why, but I commented out the line in the appDelegate: "[window makeKeyAndVisible]"

I just decompose it and build it again. Thus, the ImagePicker editing function is now executed.



I hope this help.

Lkuulu

0


source







All Articles