I am trying to attach an image and a pdf to an email using the MessageUI framework. I followed the MailComposer example in the Apple documentation.
On the iPhone it seems to work perfectly, the image and the pdf both show up in the body of the send mail window as expected.
However, when I receive the email on my MacBook there are two problems.
1) myImage.png shows up as an attachment and is the correct dimensions but is totally blank
2) myPDF.pdf doesn't show up as an attachment at all
But, when I receive the mail on my iPhone, myImage.png shows up fine. myPDF.pdf still doesn't show up in mail on my iPhone though.
Hope someone can shed some light on what might be happening.
Here is the relevant code:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Test Email"];
// Attach an image to the email
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"png"];
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
[picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"myImage"];
// Attach a PDF file to the email
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"myPDF" ofType:@"pdf"];
NSData *pdfData = [NSData dataWithContentsOfFile:pdfPath];
[picker addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"myPDF"];
// Fill out the email body text
NSString *emailBody = @"This is a test.";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
EDIT Instead of saving and retrieving my image and PDF to my mainBundle I used NSDocumentsDirectory and everything worked fine.