title: How to download large files in iOS?
body: <p>I'm trying to download files [> 40MB] from web server over HTTP request. To do that I've used the SimpleURLConnection sample provided by the apple. In that sample they only download the image files, so I modified the code to download pdf files and stored it in application's document directory. This is working fine to download small files, but it only download 6.4MB of data if I trying to download large files [>40Mb]. please help me to fix this, </p>
  
  <p>Thank you,</p>
  
  <p>FYI:</p>
  
  <p>code to write file with downloaded data</p>
  
  <pre><code>  - (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)data
      // A delegate method called by the NSURLConnection as data arrives.  We just 
      // write the data to the file.
  {
      #pragma unused(theConnection)
      NSInteger       dataLength;
      const uint8_t * dataBytes;
      NSInteger       bytesWritten;
      NSInteger       bytesWrittenSoFar;
  
      assert(theConnection == self.connection);
  
      dataLength = [data length];
      dataBytes  = [data bytes];
  
      bytesWrittenSoFar = 0;
      do {
          bytesWritten = [self.fileStream write:&amp;dataBytes[bytesWrittenSoFar] maxLength:dataLength - bytesWrittenSoFar];
          assert(bytesWritten != 0);
          if (bytesWritten == -1) {
              [self _stopReceiveWithStatus:@"File write error"];
              break;
          } else {
              bytesWrittenSoFar += bytesWritten;
          }
      } while (bytesWrittenSoFar != dataLength);
  }
  </code></pre>