我的应用程序中有按钮,当我打开时,它会显示带有附件的新电子邮件。在我向我的电子邮件地址发送电子邮件后,我收到了这条消息和附件,但附件包含我应用程序的最后一个屏幕。我想用支持文件中的附件打开这条消息。也许你知道我哪里会出错?
- (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];
最佳答案
下面是正确的解决方案:
- (IBAction)showEmail:(id)sender {
NSString *emailTitle = @"elllo";
NSString *messageBody = @"Hi ! \n Below I send you ";
NSArray *toRecipents = [NSArray arrayWithObject:@"m1891@gmail.com"];
NSString *path = [[NSBundle mainBundle] pathForResource:@"MV" ofType:@"pdf"]; NSData *myData
= [NSData dataWithContentsOfFile: path];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc addAttachmentData:myData mimeType:@"application/pdf" fileName:@"MV.pdf"];
[mc setToRecipients:toRecipents];
[self presentViewController:mc animated:YES completion:NULL];
}
关于ios - 如何在 iOS 应用程序中发送带附件(文件 PDF)的电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36421105/