From 7134e9612f0cd2865a4624000147f62e74e5fe45 Mon Sep 17 00:00:00 2001
From: Daniel Tull
Date: Wed, 19 Dec 2012 14:47:49 +0000
Subject: [PATCH] Cause a failure when an operation is cancelled, fixes #657
---
AFNetworking/AFHTTPRequestOperation.m | 4 ----
AFNetworking/AFImageRequestOperation.m | 4 ----
AFNetworking/AFJSONRequestOperation.m | 6 +-----
AFNetworking/AFPropertyListRequestOperation.m | 6 +-----
AFNetworking/AFURLConnectionOperation.m | 13 ++++++++-----
AFNetworking/AFXMLRequestOperation.m | 6 +-----
6 files changed, 11 insertions(+), 28 deletions(-)
diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m
index 2475713..091f05b 100644
--- a/AFNetworking/AFHTTPRequestOperation.m
+++ b/AFNetworking/AFHTTPRequestOperation.m
@@ -273,10 +273,6 @@ static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
self.completionBlock = ^{
- if ([self isCancelled]) {
- return;
- }
-
if (self.error) {
if (failure) {
dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
diff --git a/AFNetworking/AFImageRequestOperation.m b/AFNetworking/AFImageRequestOperation.m
index cf24f31..5346998 100644
--- a/AFNetworking/AFImageRequestOperation.m
+++ b/AFNetworking/AFImageRequestOperation.m
@@ -203,10 +203,6 @@ static dispatch_queue_t image_request_operation_processing_queue() {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
self.completionBlock = ^ {
- if ([self isCancelled]) {
- return;
- }
-
dispatch_async(image_request_operation_processing_queue(), ^(void) {
if (self.error) {
if (failure) {
diff --git a/AFNetworking/AFJSONRequestOperation.m b/AFNetworking/AFJSONRequestOperation.m
index 5401cbf..8fd0de0 100644
--- a/AFNetworking/AFJSONRequestOperation.m
+++ b/AFNetworking/AFJSONRequestOperation.m
@@ -104,11 +104,7 @@ static dispatch_queue_t json_request_operation_processing_queue() {
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
- self.completionBlock = ^ {
- if ([self isCancelled]) {
- return;
- }
-
+ self.completionBlock = ^ {
if (self.error) {
if (failure) {
dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
diff --git a/AFNetworking/AFPropertyListRequestOperation.m b/AFNetworking/AFPropertyListRequestOperation.m
index 21961d0..d454389 100644
--- a/AFNetworking/AFPropertyListRequestOperation.m
+++ b/AFNetworking/AFPropertyListRequestOperation.m
@@ -108,11 +108,7 @@ static dispatch_queue_t property_list_request_operation_processing_queue() {
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
- self.completionBlock = ^ {
- if ([self isCancelled]) {
- return;
- }
-
+ self.completionBlock = ^ {
if (self.error) {
if (failure) {
dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m
index 78a6226..1496705 100644
--- a/AFNetworking/AFURLConnectionOperation.m
+++ b/AFNetworking/AFURLConnectionOperation.m
@@ -453,15 +453,18 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
}
- (void)cancelConnection {
+
+ NSDictionary *userInfo = nil;
+ if ([self.request URL]) {
+ userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
+ }
+ self.error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo];
+
if (self.connection) {
[self.connection cancel];
// Manually send this delegate message since `[self.connection cancel]` causes the connection to never send another message to its delegate
- NSDictionary *userInfo = nil;
- if ([self.request URL]) {
- userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
- }
- [self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo]];
+ [self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:self.error];
}
}
diff --git a/AFNetworking/AFXMLRequestOperation.m b/AFNetworking/AFXMLRequestOperation.m
index d8de09a..fdb3906 100644
--- a/AFNetworking/AFXMLRequestOperation.m
+++ b/AFNetworking/AFXMLRequestOperation.m
@@ -140,11 +140,7 @@ static dispatch_queue_t xml_request_operation_processing_queue() {
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
- self.completionBlock = ^ {
- if ([self isCancelled]) {
- return;
- }
-
+ self.completionBlock = ^ {
dispatch_async(xml_request_operation_processing_queue(), ^(void) {
NSXMLParser *XMLParser = self.responseXMLParser;