PDF and MFMailComposeViewController

主宰稳场 提交于 2020-01-23 07:45:34

问题


Writing the part of the app that allows the user to generate a pdf and send it. Seems to be working fine. The sent PDF opens fine on the MAC, but on the iPhone it just keeps loading and never opens. Created a pdf document with the help of Ray Wenderlich Tutorial and sent it out through a modal view controller with a instance of an MFMailComposeViewController. WTF am i doing wrong.

Update: The PDF also opens fine on the Ipad. Could the problem be somewhere in the code for creating the PDF? Also it is a little unclear to me if I am actually creating a PDF that is persisting and then getting replaced after each new version of the same named file or am I somehow tricking the compiler into thinking a doc is getting stored so I can send it out with the least code possible.

Any thoughts on this would be appreciated.

check out the code:

if ([MFMailComposeViewController canSendMail])

{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

[picker setSubject:@"mail test"];

NSString* fileName = @"Invoice.PDF";
NSArray *arrayPaths =
NSSearchPathForDirectoriesInDomains(
                                    NSDocumentDirectory,
                                    NSUserDomainMask,
                                    YES);
NSString *path = [arrayPaths objectAtIndex:0];
NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];
NSData *myData = [NSData dataWithContentsOfFile:pdfFileName];

[picker addAttachmentData:myData mimeType:@"application/pdf" fileName:@"the PDF"];
[self presentModalViewController:picker animated:YES];

}


回答1:


try this way

 [picker addAttachmentData:myData mimeType:@"application/pdf" fileName:@"thePDF.pdf"]; 

BTW, if you are generating the PDF content just before sending it, you don't need to save to a real pdf file, just send the PDF data



来源:https://stackoverflow.com/questions/12119524/pdf-and-mfmailcomposeviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!