0

我有一个名为 FlashCards.pdf 的 pdf 文件

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

NSArray *recipients = @[@"aarone_2010@hotmail.com"];

// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"FlashCards" ofType:@"pdf"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"application/pdf" fileName:@"FlashCards"];
[picker setSubject:@"Flashcards"];
[picker setToRecipients:recipients];
[picker setMessageBody:@"Hello" isHTML:NO];
[picker setMailComposeDelegate:self];
[self presentViewController:picker animated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];

正在发送电子邮件,似乎一切正常,但没有发送 PDF 文件。

编辑:

这实际上有效,我在代码的其他部分遇到了其他问题。我的问题解决了。我还确保扩展名是正确的,而不是将 FlashCards 作为文件名,它应该是 FlashCards.pdf 这是我工作的确切代码:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
NSArray *recipients = @[@"android.aaron.david@gmail.com"];
NSString *path = [[NSBundle mainBundle] pathForResource:@"FlashCards" ofType:@"pdf"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"application/pdf" fileName:@"FlashCards.pdf"];
[picker setSubject:@"Flashcards"];
[picker setToRecipients:recipients];
[picker setMessageBody:@"Hello" isHTML:NO];
[picker setMailComposeDelegate:self];
[self presentViewController:picker animated:YES completion:nil];
4

1 回答 1

0

使用 MIME 类型text/x-pdf而不是application/pdf. 还要检查大小/长度myData以验证 PDF 是否已加载。

于 2014-06-09T15:51:54.093 回答