Note that there are some explanatory texts on larger screens.

plurals
  1. POdefunct NSURLConnection never executes or times out
    primarykey
    data
    text
    <p>I'm running a LOT of asynchronous (delegate, not block) <code>NSURLConnections</code> simultaneously, and they all come back very quickly as I'm hitting a LAN server.</p> <p>Every so often, one <code>NSURLConnection</code> will go defunct and never return.</p> <p><code>connection:willSendRequest:</code> is called but <code>connection:didReceiveResponse:</code> (and failure) is not.</p> <p>Any ideas? I'm wondering if I should make a simple drop-in replacement using <code>CFNetwork</code> instead.</p> <p>Edit: There's really not much code to show. What I've done is created a wrapper class to download files. I will note that the problem happens <em>less</em> when I run the connection on a separate queue - but still happens.</p> <p>The general gist of what I'm doing is creating a download request for each cell as a tableview scrolls (in <code>cellForRowAtIndexPath</code>) and then asynchronously loading in an image file to the table cell if the cell is still visible.</p> <pre><code>_request = [NSMutableURLRequest requestWithURL:_URL]; _request.cachePolicy = NSURLRequestReloadIgnoringCacheData; _request.timeoutInterval = _timeoutInterval; if(_lastModifiedDate) { [_request setValue:[_lastModifiedDate RFC1123String] forHTTPHeaderField:@"If-Modified-Since"]; } _connection = [[NSURLConnection alloc] initWithRequest:_request delegate:self startImmediately:NO]; [_connection start]; </code></pre> <p>As requested, instance variables:</p> <pre><code>NSMutableURLRequest *_request; NSURLConnection *_connection; </code></pre> <p>And delegate methods:</p> <pre><code>- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response { NSLog(@"%@ send", _URL); return request; } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSLog(@"%@ response", _URL); _response = (id)response; // create output stream } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { _receivedLength += data.length; _estimatedProgress = (Float32)_receivedLength / (Float32)_response.expectedContentLength; [_outputStream write:data.bytes maxLength:data.length]; // notify delegate } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { // close output stream // notify delegate } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog(@"%@ failure", _URL); // notify delegate } - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { if(_credential &amp;&amp; challenge.previousFailureCount == 0) { [[challenge sender] useCredential:_credential forAuthenticationChallenge:challenge]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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