我想使用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