title: In iPhone 3.0, Application crashes when trying to send an image from the camera using MessageUI
body: <p>There is a part of the iPhone app that I'm developing where you can send images using the in app mail in iPhone 3.0. Selecting an image from the camera roll works perfectly, but when I try to go from the camera to the email (ie - from the UIImagePickerController to the MFMailComposeViewController), the application crashes. </p>
  
  <p>This is the code for running the camera : </p>
  
  <pre><code>- (BOOL)startCameraPickerFromViewController:(UIViewController*)controller usingDelegate:(id&lt;UIImagePickerControllerDelegate, UINavigationControllerDelegate&gt;)delegateObject 
  {
      if ( (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) || (delegateObject == nil) || (controller == nil)) 
          return NO;
      UIImagePickerController* picker = [[UIImagePickerController alloc] init];
      picker.sourceType = UIImagePickerControllerSourceTypeCamera;
      picker.delegate = delegateObject;
      picker.allowsImageEditing = NO;
      [controller presentModalViewController:picker animated:YES];
      return YES;
  }
  </code></pre>
  
  <p>And this is the code for finishing with the camera  : </p>
  
  <pre><code>- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
  {
      NSLog(@"Called finish picking");
      self.imageForSending = theImage;
  
      //   NSData *imageData = UIImageJPEGRepresentation(image, 1);
  
      [[picker parentViewController] dismissModalViewControllerAnimated:YES];
      [(ChannelTwoAppDelegate *) [[UIApplication sharedApplication] delegate] recoverNavigationBar];
  
      [self performSelector:@selector(sendEmail) withObject:nil afterDelay:0.45];
      [picker release];
  }
  </code></pre>
  
  <p>And this is the code for sending the mail  : </p>
  
  <pre><code>- (void) sendEmail {
  
      [(ChannelTwoAppDelegate *) [[UIApplication sharedApplication] delegate] hideNavigationBar];
      if (![MFMailComposeViewController canSendMail])
      {
          UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"שגיאה", @"") message:NSLocalizedString(@"לא ניתן לשלוח מייל ממכשיר זה", @"")
                                                         delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
          [alert show];   
          [alert release];
      }
      else
      {
          MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
          controller.mailComposeDelegate = self;
          [[controller navigationBar] setTintColor:[UIColor colorWithRed:120.0/255.0 green:0 blue:0 alpha:1.0]];
          NSData *imageData = UIImageJPEGRepresentation(imageForSending, 1);
          [controller addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"storyImage.jpg"];
          [controller setSubject:@""];
          [controller setToRecipients:[NSArray arrayWithObject:@""]];
          [self presentModalViewController:controller animated:YES];
          [controller release];
      }
  
  }
  </code></pre>
  
  <p>I erased the email address and the subject since it is less relevant. </p>
  
  <p>The crash happens at presentModalViewController of the email. Again - this exact code work perfectly when selecting an image from the camera roll... </p>
  
  <p>Help ? 
  I've been fighting with this one for a while and could really use some new input. 
  Thanks!</p>