Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding support for download progress block when an output block is used

  • Loading branch information...
commit 8de22e8f99ea788b836e7b2aa05ea6bcc37f51c1 1 parent 59a98bb
@mattt mattt authored
Showing with 10 additions and 4 deletions.
  1. +10 −4 AFNetworking/AFHTTPRequestOperation.m
View
14 AFNetworking/AFHTTPRequestOperation.m
@@ -79,6 +79,7 @@ static inline BOOL AFHTTPOperationStateTransitionIsValid(AFHTTPOperationState fr
@interface AFHTTPRequestOperation ()
@property (nonatomic, assign) AFHTTPOperationState state;
@property (nonatomic, assign) BOOL isCancelled;
+@property (readwrite, nonatomic, assign) NSUInteger totalBytesRead;
@property (readwrite, nonatomic, retain) NSMutableData *dataAccumulator;
@property (readwrite, nonatomic, retain) NSOutputStream *outputStream;
@property (readwrite, nonatomic, copy) AFHTTPRequestOperationProgressBlock uploadProgress;
@@ -97,6 +98,7 @@ @implementation AFHTTPRequestOperation
@synthesize response = _response;
@synthesize error = _error;
@synthesize responseBody = _responseBody;
+@synthesize totalBytesRead = _totalBytesRead;
@synthesize dataAccumulator = _dataAccumulator;
@synthesize outputStream = _outputStream;
@synthesize uploadProgress = _uploadProgress;
@@ -301,6 +303,8 @@ - (void)connection:(NSURLConnection *)connection
- (void)connection:(NSURLConnection *)connection
didReceiveData:(NSData *)data
{
+ self.totalBytesRead += [data length];
+
if (self.outputStream) {
if ([self.outputStream hasSpaceAvailable]) {
const uint8_t *dataBuffer = [data bytes];
@@ -308,10 +312,10 @@ - (void)connection:(NSURLConnection *)connection
}
} else {
[self.dataAccumulator appendData:data];
+ }
- if (self.downloadProgress) {
- self.downloadProgress([self.dataAccumulator length], self.response.expectedContentLength);
- }
+ if (self.downloadProgress) {
+ self.downloadProgress(self.totalBytesRead, self.response.expectedContentLength);
}
}
@@ -348,7 +352,9 @@ - (void)connection:(NSURLConnection *)connection
}
}
-- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse {
+- (NSCachedURLResponse *)connection:(NSURLConnection *)connection
+ willCacheResponse:(NSCachedURLResponse *)cachedResponse
+{
if ([self isCancelled]) {
return nil;
}
Please sign in to comment.
Something went wrong with that request. Please try again.