【发布时间】:2016-04-05 08:34:28
【问题描述】:
我的应用程序中有按钮,当我打开时,它会显示带有附件的新电子邮件。将电子邮件发送到我的电子邮件地址后,我收到了此消息和附件,但附件包含我的应用程序的最后一个屏幕。我想打开此消息,其中包含来自支持文件的附件。也许你知道我哪里出错了?
- (IBAction)showEmail:(id)sender {
NSString *emailTitle = @"elllo";
NSString *messageBody = @"Hi ! \n Below I send you ";
NSArray *toRecipents = [NSArray arrayWithObject:@"m1891@gmail.com"];
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, self.view.bounds, nil);
UIGraphicsBeginPDFPage();
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndPDFContext();
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"MV.pdf"];
[mc setToRecipients:toRecipents];
[self presentViewController:mc animated:YES completion:NULL];
}
【问题讨论】:
-
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];表示您正在制作屏幕截图,绘制实际的 PDF 本身
-
好的,谢谢@ogres!如何从支持文件发送带有附件(文件 pdf)的电子邮件?
-
您可以先将文件读取为 NSData,然后附加该数据
标签: ios objective-c mfmailcomposeviewcontroller