PDF和MFMailComposeViewController [英] PDF and MFMailComposeViewController

查看:110
本文介绍了PDF和MFMailComposeViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写应用程序中允许用户生成pdf并将其发送的部分.似乎工作正常.发送的PDF在MAC上可以正常打开,但是在iPhone上,它一直保持加载状态,并且永远不会打开.在Ray Wenderlich教程的帮助下创建了一个pdf文档,并通过带有MFMailComposeViewController实例的模式视图控制器将其发送出去. WTF我做错了.

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.

更新:PDF也可以在Ipad上正常打开.问题可能出在创建PDF的代码中吗?同样,对于我来说是否真正创建持久存在的PDF,然后在同一个命名文件的每个新版本中都被替换,还是我以某种方式诱使编译器认为文档已被存储,以便我可以发送它,这对我来说还是一个不清楚的地方.用最少的代码.

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.

检查代码:

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];

}

推荐答案

尝试这种方式

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

顺便说一句,如果要在发送PDF内容之前就生成它,则无需保存为真实的pdf文件,只需发送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

这篇关于PDF和MFMailComposeViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆