diff --git a/AFNetworking/AFURLConnectionOperation.h b/AFNetworking/AFURLConnectionOperation.h index c8c9487..cc7d93f 100644 --- a/AFNetworking/AFURLConnectionOperation.h +++ b/AFNetworking/AFURLConnectionOperation.h @@ -197,7 +197,9 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; /** Sets a callback to be called when an undetermined number of bytes have been uploaded to the server. - @param block A block object to be called when an undetermined number of bytes have been uploaded to the server. This block has no return value and takes three arguments: the number of bytes written since the last time the upload progress block was called, the total bytes written, and the total bytes expected to be written during the request, as initially determined by the length of the HTTP body. This block may be called multiple times. + @param block A block object to be called when an undetermined number of bytes have been uploaded to the server. This block has no return value and takes three arguments: the number of bytes written since the last time the upload progress block was called, the total bytes written, and the total bytes expected to be written during the request, as initially determined by the length of the HTTP body. This block may be called multiple times, and will execute on the main thread. + + @discussion This block is called on the main thread. @see setDownloadProgressBlock */ @@ -206,8 +208,8 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; /** Sets a callback to be called when an undetermined number of bytes have been downloaded from the server. - @param block A block object to be called when an undetermined number of bytes have been downloaded from the server. This block has no return value and takes three arguments: the number of bytes read since the last time the download progress block was called, the total bytes read, and the total bytes expected to be read during the request, as initially determined by the expected content size of the `NSHTTPURLResponse` object. This block may be called multiple times. - + @param block A block object to be called when an undetermined number of bytes have been downloaded from the server. This block has no return value and takes three arguments: the number of bytes read since the last time the download progress block was called, the total bytes read, and the total bytes expected to be read during the request, as initially determined by the expected content size of the `NSHTTPURLResponse` object. This block may be called multiple times, and will execute on the main thread. + @see setUploadProgressBlock */ - (void)setDownloadProgressBlock:(void (^)(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))block; diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index fdacb36..7defb7f 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -539,7 +539,9 @@ didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite { if (self.uploadProgress) { - self.uploadProgress(bytesWritten, totalBytesWritten, totalBytesExpectedToWrite); + dispatch_async(dispatch_get_main_queue(), ^{ + self.uploadProgress(bytesWritten, totalBytesWritten, totalBytesExpectedToWrite); + }); } } @@ -562,7 +564,9 @@ didReceiveResponse:(NSURLResponse *)response } if (self.downloadProgress) { - self.downloadProgress((long long)[data length], self.totalBytesRead, self.response.expectedContentLength); + dispatch_async(dispatch_get_main_queue(), ^{ + self.downloadProgress((long long)[data length], self.totalBytesRead, self.response.expectedContentLength); + }); } }