我正在尝试通过电子邮件发送PDF页面。
以下是我的尝试:
CGPDFDocumentRef SourcePDFDocument = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"myPDF" ofType:@"pdf"]]); // Create the CGPDFDocument from the URL
if (SourcePDFDocument == NULL) {
return nil;
}
CGPDFPageRef SourcePDFPage = CGPDFDocumentGetPage(SourcePDFDocument, pageNumber);
CGRect mediaBox = CGPDFPageGetBoxRect(SourcePDFPage, kCGPDFMediaBox);
NSData *outputData;
CGDataConsumerRef consumer = CGDataConsumerCreateWithCFData((__bridge CFMutableDataRef)outputData);
CGContextRef context = CGPDFContextCreate(consumer, &mediaBox, NULL);
CGContextBeginPage(context, &mediaBox);
CGContextDrawPDFPage(context, SourcePDFPage);
CGContextEndPage(context);
CGDataConsumerRelease(consumer);
CGContextRelease(context);
NSString *emailSubject = @"Subject";
NSString *messageBody = @"message";
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailSubject];
[mc setMessageBody:messageBody isHTML:NO];
[mc addAttachmentData:outputData mimeType:@"application/pdf" fileName:@"thePage.pdf"];
[self presentViewController:mc animated:YES completion:NULL];
但它失败了,收到电子邮件时没有附件
我也收到此错误