0

This is iPhone app code but when i run into ipad retina simulator or
ipad then it's crash the app. i have check many times & i realise
the picker object is nil. but it's works good on iPhone simulator . Any one any Idea about this thing.(This app made only iPhone but run in iPad Retina & iPad)

UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init]; // image picker alloc 
imagePicker.delegate = self; // delegate call by self

imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //Pick image in Library
[self presentModalViewController:imagePicker animated:YES]; // OPen Library


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info                
{
    imgImage = info[UIImagePickerControllerOriginalImage]; //Get Orginial Images
    imgData = [[NSData alloc] initWithData:UIImageJPEGRepresentation((imgImage), 0.9)]; // Jpg image format
    [picker dismissModalViewControllerAnimated:YES];
} // pick image from this method
Sandy Patel
  • 768
  • 7
  • 19
  • When it crashes, what specifically is the error message displayed in the debugger? – Jeff C. Sep 23 '14 at 08:58
  • *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: Image)' Please Help me if you know this thing. – Sandy Patel Sep 23 '14 at 09:07
  • What are the contents of the line that it crashes on? Can you provide it (and any surrounding lines, if possible)? – Jeff C. Sep 23 '14 at 09:22
  • It might also help for debugging purposes to print out the returned NSDictionary, like so: NSLog(@"info = %@", info); – Jeff C. Sep 23 '14 at 09:24
  • UIImage *myImage =[info objectForKey:UIImagePickerControllerOriginalImage]; I got nil myImage nil. & crash on other line. – Sandy Patel Sep 23 '14 at 10:45

1 Answers1

0

Try this...This method is called when an image has been chosen from the library or taken from the camera.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
    NSData *imgData = UIImagePNGRepresentation(image);

    [picker dismissModalViewControllerAnimated:YES];

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:NULL];
}
Pawan Rai
  • 3,434
  • 4
  • 32
  • 42
Deepak
  • 1,421
  • 1
  • 16
  • 20
  • Error:- *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: Image)' – Sandy Patel Sep 23 '14 at 09:42