title: what is the best way to download large amount of images from server to the ipad?
body: <p>we are currently developing an enterprise app for our company.The app is supposed to work offline, This means we need to download more than 10K product images to the iPad.Each image can be from several KB to 4M.For doing so at first we used the following code to download images:</p>
  
  <pre><code>-(BOOL)DownloadFileInBatch :(NSArray*) fileArr
  {
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  
      NSString *documentDirectory = [paths objectAtIndex:0];
  
      NSOperationQueue *queue = [[NSOperationQueue alloc] init];
      queue.maxConcurrentOperationCount = 4;
  
      NSBlockOperation *completionOperation = [NSBlockOperation blockOperationWithBlock:^{
          [[NSOperationQueue mainQueue] addOperationWithBlock:^{
              [[NSNotificationCenter defaultCenter] postNotificationName:@"taskDone" object:self];
          }];
      }];
  
      @autoreleasepool
      {
          NSBlockOperation *operation;
  
          for(int i = 0; i &lt; fileArr.count; i++)
          {
               operation = [NSBlockOperation blockOperationWithBlock:^{
  
                  NSURL *url = [[NSURL alloc] initWithString:[[fileArr objectAtIndex:i] objectForKey:@"image_url"]];
  
                  NSData *data = [NSData dataWithContentsOfURL:url];
  
                  NSString *filename = [documentDirectory stringByAppendingString:[NSString stringWithFormat:@"/%@", [url lastPathComponent]]];
  
                  NSLog(@"downloading file : %@ : no : %d", [documentDirectory stringByAppendingString:[NSString stringWithFormat:@"/%@", [url lastPathComponent]]], i);
  
                  BOOL success = [data writeToFile:filename atomically:YES];
  
                  if(!success)
                  {
                     // failed to download
                  }
              }];
  
              [completionOperation addDependency:operation];
          }
      }
  
      [queue addOperations:completionOperation.dependencies waitUntilFinished:NO];
      [queue addOperation:completionOperation];
  
      return YES;
  }
  </code></pre>
  
  <p>But when we are using this code to download, the app crash due to memory problem.(even putting @autoreleasepool did not solve the crashing problem). It seems downloading one-by-one (or even 4 images parallel)is not a suitable option for this amount of data since it cause us memory problem.I just want to know what is the best way to download this amount of images from server to the iPad?</p>
  
  <p>Thanks in advance...</p>