Permalink
Browse files

Hide network activity indicator *before* calling completion block.

  • Loading branch information...
1 parent 48b765d commit edcd3977d9f6d4c979c177c3a0f0a31ca9e2fed3 @samvermette samvermette committed Jan 22, 2012
Showing with 11 additions and 10 deletions.
  1. +11 −10 SVHTTPRequest/SVHTTPRequest.m
@@ -54,6 +54,7 @@ - (void)addParametersToRequest:(NSDictionary*)paramsDict;
- (void)finish;
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;
+- (void)callCompletionBlockWithResponse:(id)response error:(NSError*)error;
@end
@@ -273,16 +274,14 @@ - (void)finish {
self.state = SVHTTPRequestStateFinished;
[self didChangeValueForKey:@"isExecuting"];
[self didChangeValueForKey:@"isFinished"];
-
- [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
- (void)cancel {
if([self isFinished])
return;
[super cancel];
- [self finish];
+ [self callCompletionBlockWithResponse:nil error:nil];
}
- (BOOL)isConcurrent {
@@ -342,17 +341,19 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
response = jsonObject;
}
- if(self.operationCompletionBlock)
- self.operationCompletionBlock(response, nil);
-
- [self finish];
+ [self callCompletionBlockWithResponse:response error:nil];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
self.timeoutTimer = nil;
-
- NSLog(@"requestFailed: %@", [error localizedDescription]);
- self.operationCompletionBlock(nil, error);
+ [self callCompletionBlockWithResponse:nil error:error];
+}
+
+- (void)callCompletionBlockWithResponse:(id)response error:(NSError *)error {
+ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
+
+ if(self.operationCompletionBlock && (response || error))
+ self.operationCompletionBlock(response, error);
[self finish];
}

0 comments on commit edcd397

Please sign in to comment.