From 580c5476168284abe5e53590d9536e063edddb81 Mon Sep 17 00:00:00 2001 From: Oliver Letterer Date: Tue, 26 Feb 2013 08:37:18 +0100 Subject: [PATCH] Fixes -[AFURLConnectionOperation totalBytesRead] threading issue. --- AFNetworking/AFURLConnectionOperation.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 1fc61db..5503e68 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -628,18 +628,18 @@ didReceiveResponse:(NSURLResponse *)response - (void)connection:(NSURLConnection __unused *)connection didReceiveData:(NSData *)data { - self.totalBytesRead += [data length]; - if ([self.outputStream hasSpaceAvailable]) { const uint8_t *dataBuffer = (uint8_t *) [data bytes]; [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); - }); - } + } + }); } - (void)connectionDidFinishLoading:(NSURLConnection __unused *)connection {