Fixes -[AFURLConnectionOperation totalBytesRead] threading issue.

This commit is contained in:
Oliver Letterer 2013-02-26 08:37:18 +01:00
parent cb3744a808
commit 580c547616

View file

@ -628,18 +628,18 @@ didReceiveResponse:(NSURLResponse *)response
- (void)connection:(NSURLConnection __unused *)connection - (void)connection:(NSURLConnection __unused *)connection
didReceiveData:(NSData *)data didReceiveData:(NSData *)data
{ {
self.totalBytesRead += [data length];
if ([self.outputStream hasSpaceAvailable]) { if ([self.outputStream hasSpaceAvailable]) {
const uint8_t *dataBuffer = (uint8_t *) [data bytes]; const uint8_t *dataBuffer = (uint8_t *) [data bytes];
[self.outputStream write:&dataBuffer[0] maxLength:[data length]]; [self.outputStream write:&dataBuffer[0] maxLength:[data length]];
} }
if (self.downloadProgress) { dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{ self.totalBytesRead += [data length];
if (self.downloadProgress) {
self.downloadProgress([data length], self.totalBytesRead, self.response.expectedContentLength); self.downloadProgress([data length], self.totalBytesRead, self.response.expectedContentLength);
}); }
} });
} }
- (void)connectionDidFinishLoading:(NSURLConnection __unused *)connection { - (void)connectionDidFinishLoading:(NSURLConnection __unused *)connection {