使用asihttprequest下载/检索pdf
我试图通过这个函数在我的iPad(cachedDir?)下载带有URL的内容到本地文件系统:
- (IBAction)download:(id)sender { NSURL *url = [NSURL URLWithString:@"http:www.google.de"]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setDelegate:self]; [request startAsynchronous]; [request setDownloadDestinationPath:@"/Users/ben/Desktop/my_file.pdf"]; // Which //directory?? }
如果我想尽可能长时间地存储数据而不被Apple拒绝,那么我需要为我的pathselect哪个目录?如何检索我已经保存的数据?
有人可以帮忙吗?
存储您想要保留的文档的最佳位置是您的应用程序的文档直接。 你可以像这样find它的path:
// Returns the URL to the application's Documents directory. - (NSURL *)applicationDocumentsDirectory { return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; }
苹果有一个关于iOS文件系统的文档,以及在哪里存储特定types的文件: http : //developer.apple.com/library/mac/#documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/FileSystemOverview/FileSystemOverview.html
试试这个我的代码保存PDF文档使用下面的代码
NSString *downloadUrl=[NSURL URLWithString:@"http:www.google.de"]; NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:downloadUrl]]; //Store the Data locally as PDF File NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]]; NSString *pdf1 = @"title.pdf"; NSString *filePath = [resourceDocPath stringByAppendingPathComponent:pdf1]; [pdfData writeToFile:filePath atomically:YES];
并回顾你的文件使用
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSURL *pdfURL = [[NSBundle bundleWithPath:[paths objectAtIndex:0]] URLForResource:[NSString stringWithFormat:@"title.pdf"] withExtension:nil]; NSLog(@"pDF URl %@", pdfURL); pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
- NSURLConnection下载大文件(> 40MB)
- MonoTouch:如何保存一个巨大的PDF增量下载的URL?
- 从内存中下载并保存大量图像时的iOS内存问题(ARC)
- BackgroundSession SessionDownloadTasklocking屏幕时,错误:NSPOSIXErrorDomain Code = 1
- 方法resolvePolicyForNavigationAction有时不被调用
- MonoTouch:如何按照苹果幻灯片“build立报刊应用程序”(Session 504)中的说明逐步下载PDF?
- AFNetworking QUEUE与pdf,png,mp4文件
- 如何使用Graph API下载上传到私人Facebook群组的文件
- 如何在不使用第三方库的情况下在swift2中下载页面?