CGPDFDocumentCreateWithURL 是否将文件下载到文档目录

发布于 2024-11-05 04:14:43 字数 267 浏览 1 评论 0原文

我正在使用 iPhone 并通过将文件 url 传递给 CGPDFDocumentCreateWithURL 来访问 PHP 服务器中可用的 PDF 文件。我的问题是,每当我访问文件时,它是否会下载到我的 iPhone 文档目录中?

因为如果我的应用程序处于活动状态一段时间,我会收到错误 CFURLCreateDataAndPropertiesFromResource ,错误代码为 -14。收到此错误后,我的应用程序没有崩溃,但无法正常运行。

我无法理解内部流程?请帮我解决这个问题?

I am accessing the PDF files available in my PHP server using my iPhone with the help of passing file url to CGPDFDocumentCreateWithURL. My question whenever i access the files it will downloaded to my iphone documents directory or not?

Because if my application in active for some time i am getting the error CFURLCreateDataAndPropertiesFromResource with error code -14. After getting this error my application is not crashed but it is not functioning properly.

I am not able to understand the internal process? Please help me in this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

虚拟世界 2024-11-12 04:14:44

我认为您误解了 CGPDFDocumentCreateWithURL 的作用。它不会将 PDF 文档下载到文件系统。它根据提供的 URL 在内存中创建 PDF。它不会将任何内容保存到文件系统中。

强烈建议您使用网络类(NSURLConnection、ASI 等)首先下载 PDF,然后打开它。这将使您能够提供更好的反馈,并支持更高级的下载功能,例如恢复部分下载、提供进度和更好的线程管理。

I think you're misunderstanding what CGPDFDocumentCreateWithURL does. It does not download a PDF document to the filesystem. It creates a PDF in memory based off the URL provided. It doesn't save anything to the filesystem.

I would strongly recommend you use a networking class (NSURLConnection, ASI, etc) to download the PDF first and then open it. This will enable you to provide better feedback, and support more advanced download features such as resuming partial downloads, providing progress, and better thread management.

孤者何惧 2024-11-12 04:14:44

要保存 PDF

NSString *urlString = @"http://www.web.com/url/for/document.pdf";

NSURL *url = [NSURL URLWithString:urlString];

NSData *data = [NSData dataWithContentsOfURL:url];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"myLocalFileName.pdf"];

[data writeToFile:pdfPath atomically:YES];

,然后将该保存的文件加载到 Web 视图中:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"myLocalFileName.pdf"];

NSURL *url = [NSURL fileURLWithPath: pdfPath];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

[[self mainWebView] loadRequest:request];

To save the PDF

NSString *urlString = @"http://www.web.com/url/for/document.pdf";

NSURL *url = [NSURL URLWithString:urlString];

NSData *data = [NSData dataWithContentsOfURL:url];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"myLocalFileName.pdf"];

[data writeToFile:pdfPath atomically:YES];

then load that saved file into a web view:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"myLocalFileName.pdf"];

NSURL *url = [NSURL fileURLWithPath: pdfPath];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

[[self mainWebView] loadRequest:request];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文