0

I am trying to email a UIImage from my app. In my app I take a picture and then set a UIImageView to the picture that was just taken. Then I have a button which should email that picture as an attachment, like this:

- (IBAction)emailPhoto:(UIButton *)sender {
sendImage = imageView.image;
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if([MFMailComposeViewController canSendMail]) {
    [composer setToRecipients:[NSArray arrayWithObjects:@"JanJaap@Korteweg.nl",nil]];
    [composer setSubject:@"A nice subject"];
    [composer setMessageBody:@"Hi,\n\nI'm sending you this beautiful photograph." isHTML:NO];
    [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];

    NSData *data = UIImageJPEGRepresentation(sendImage,1);
    [composer addAttachmentData:data  mimeType:@"image/jpeg" fileName:@"Photograph.jpg"];

    [self presentViewController:composer animated:YES completion:nil];
    }
}

For some reason when I call this I get the composer window but it remains kind of greyed out and I can't edit anything (put in email address, type in body, etc). Also no attachment shows up. I deleted the image code and tried again and it all worked so the problem is somewhere in my handling of the image, but I am at a loss as to what that might be and I get no errors at all or warnings. I have tried a number of other strategies including bas64 encoding and saving the photo to the photo library and then retrieving it but they seem too complicated and result in never ending chains of warnings and errors. Any help appreciated. Thanks!

Max von Hippel
  • 2,856
  • 3
  • 29
  • 46

0 Answers0