我想使用MessageUI框架将图像和PDF附加到电子邮件。我遵循Apple文档中的MailComposer示例。iPhone MessageUI电子邮件附件没有被发送到接收器
在iPhone上,它看起来很完美,图像和PDF都在预期发送邮件窗口的主体中显示。
但是,当我在我的MacBook上收到电子邮件时,存在两个问题。
1)myImage.png显示为一个附件,是正确的尺寸,而是可以完全空白
2)myPDF.pdf不显示为在所有
附件但是,当我收到我的iPhone上的邮件,myImage.png显示正常。 myPDF.pdf仍然不会在我的iPhone上显示在邮件中。
希望有人可以对可能发生的事情有所了解。
下面是相关代码:相反,保存和检索我的形象和PDF我mainBundle我用NSDocumentsDirectory和一切工作的罚款
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];
编辑。
实际上这并不是必需的,因为文件类型已经在pathForResource中指定:ofType:但是,无论如何,我确实尝试过,并没有区别。 – jj0b 2010-02-18 16:16:58
pathForResourceOfType是关于*加载*的数据,而fileName参数可能已经影响了电子邮件客户端如何解释*数据....您可以发布电子邮件转储,因为您在Mac上收到它? – 2010-02-19 04:11:32