Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS NSURLConnection not downloading files from certain URLs
    text
    copied!<p>I have an <code>NSURLConnection</code> in a tableview cell subclass that can download most files. I noticed, however, that some fail to start downloading, and time out. An example would be <a href="http://download.thinkbroadband.com/10MB.zip">this</a> URL, which is just a test zip file that downloads fine in any other browser. Heres my code for the download</p> <pre><code>-(void)downloadFileAtURL:(NSURL *)url{ self.downloadedData = [[NSMutableData alloc] init]; self.url = url; conn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:self.url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:1200.0] delegate:self startImmediately:YES]; } - (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSHTTPURLResponse*)response { int statusCode = [response statusCode]; if (statusCode == 200){ self.fileName.text = response.URL.lastPathComponent; self.respo = response; expectedLength = [response expectedContentLength]; } } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ [self.downloadedData appendData:data]; } - (void)connectionDidFinishLoading:(NSURLConnection *)connection{ CFStringRef mimeType = (__bridge CFStringRef)[_respo MIMEType]; CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeType, NULL); CFStringRef extension = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension); NSString *fileName = [NSString stringWithFormat:@"%@.%@", [[_respo suggestedFilename] stringByDeletingPathExtension], (__bridge NSString *)extension]; [[NSFileManager defaultManager] createFileAtPath:[[self docsDir] stringByAppendingPathComponent:[NSString stringWithFormat:@"Downloads/%@", fileName]] contents:_downloadedData attributes:nil]; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ NSLog(@"Download failed with error: %@", error); } </code></pre> <p>Anybody see anything that might cause this?</p> <p>Heres the error:</p> <pre><code>Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x1fd2c650 {NSErrorFailingURLStringKey=http://download.thinkbroadband.com/10MB.zip, NSErrorFailingURLKey=http://download.thinkbroadband.com/10MB.zip, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x1fdc90b0 "The request timed out."} </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload