问题描述
如何将PDF文档从网上下载到我的应用程序的Document文件夹中?
How can I download a PDF document from the web to my apps Document folder?
我想在启动应用程序时从网上获取PDF版本,并在应用程序中使用它.需要将其复制到Apps Documents文件夹,以便可以从那里使用它,直到再次启动该应用程序为止.显然,我需要检查文档上的日期戳,以查看是否需要更新它.也许有一种方法可以检查PDF元数据中的版本号?
I want to grab a version of a PDF from the web as an application is launched and use this in the app. It will need to be copied to the Apps Documents folder so it can be used from there until the app is launched again. Obviously I will need to check the date stamp on the doc to see if we need to update it. Maybe there's a way to check the PDF metadata for a version number?
推荐答案
又快又脏-没有错误检查,也没有使用NSURLConnection及其委托协议会收到的不错的回调(如果您愿意的话,可能会很不错)收到错误,进度等通知)
Quick and dirty -- no error checking and no nice callbacks that you would receive from using NSURLConnection and its delegate protocol (which may be nice if you want to be notified of errors, progress, etc.)
// fileURL is an NSURL that points to your pdf file
NSData *fileData = [NSData dataWithContentsOfURL:fileURL];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *localFilename = [(NSString *)[paths objectAtIndex:0] stringByAppendingPathComponent:@"myPDF"];
[fileData writeToFile:localFilename atomically:YES];
这篇关于如何从Web将PDF文档下载到我的iPhone应用程序的Document文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!