-1

I'm trying to download content with an URL to a local file system in my iPad (cachedDir ? ) with this function:

- (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??

}

Which directory do I have to choose for my path if I want to store the data as long as possible without getting rejected by Apple, and how do I retrieve the data I've saved?

Can somebody help?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Julian Herbold
  • 537
  • 9
  • 20

2 Answers2

1

The best place to store documents that you want to keep around is your application's Documents directly. You can find the path to it like so:

// Returns the URL to the application's Documents directory.
- (NSURL *)applicationDocumentsDirectory
{
    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}

Apple have a useful piece of documentation about the iOS file system and where to store particular types of files: http://developer.apple.com/library/mac/#documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/FileSystemOverview/FileSystemOverview.html

James Frost
  • 6,960
  • 1
  • 33
  • 42
0

Try out this my code for save pdf in document using below code

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

and retrive your file using

 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);
Hiren
  • 12,720
  • 7
  • 52
  • 72
  • thx for the code by now, but the code shows an synchronous download or? i forgot to say that it should be asynchronous – Julian Herbold Aug 24 '12 at 08:51
  • then follow the link of asynchronous download http://stackoverflow.com/questions/12103308/how-to-monitor-pdf-download-process-in-iphone-sdk/12103472#comment16178593_12103472 – Hiren Aug 24 '12 at 08:52
  • mho this download function is hard for me 2 customize, also because i don't have a progress indicator showing up – Julian Herbold Aug 24 '12 at 09:18
  • ok then do one thing remove self.av and remove sentences of myProgressIndicator it's not affect to your task – Hiren Aug 24 '12 at 09:24
  • can't set @property (nonatomic, retain) ASIHTTPRequest *rqstForAudio; without getting error "unknown type name" :/ – Julian Herbold Aug 24 '12 at 09:36
  • what about this function? seems more straight forward http://stackoverflow.com/questions/8116555/is-this-the-correct-way-of-downloading-a-file-with-asihttprequest?rq=1 – Julian Herbold Aug 24 '12 at 09:44