Added methods to simplify calling the success/failure handlers.
This commit is contained in:
parent
feaf0814c4
commit
30a5cea4fc
6 changed files with 51 additions and 59 deletions
|
|
@ -107,3 +107,18 @@
|
||||||
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
|
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@interface AFHTTPRequestOperation (AFInternal)
|
||||||
|
|
||||||
|
/**
|
||||||
|
Executes the successBlock on the corresponding successCallbackQueue.
|
||||||
|
*/
|
||||||
|
- (void)dispatchSuccessBlock:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successBlock responseObject:(id)responseObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Executes the failureBlock on the corresponding failureCallbackQueue.
|
||||||
|
*/
|
||||||
|
- (void)dispatchFailureBlock:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureBlock error:(NSError *)error;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
@ -127,17 +127,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.error) {
|
if (self.error) {
|
||||||
if (failure) {
|
[self dispatchFailureBlock:failure error:self.error];
|
||||||
dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
|
||||||
failure(self, self.error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (success) {
|
[self dispatchSuccessBlock:success responseObject:self.responseString];
|
||||||
dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{
|
|
||||||
success(self, self.responseData);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -148,4 +140,23 @@
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - AFInternal
|
||||||
|
|
||||||
|
- (void)dispatchSuccessBlock:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successBlock responseObject:(id)responseObject {
|
||||||
|
if (successBlock) {
|
||||||
|
dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{
|
||||||
|
successBlock(self, responseObject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)dispatchFailureBlock:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureBlock error:(NSError *)error {
|
||||||
|
if (failureBlock) {
|
||||||
|
dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
||||||
|
failureBlock(self, error);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -230,17 +230,9 @@ static dispatch_queue_t image_request_operation_processing_queue() {
|
||||||
|
|
||||||
dispatch_async(image_request_operation_processing_queue(), ^(void) {
|
dispatch_async(image_request_operation_processing_queue(), ^(void) {
|
||||||
if (self.error) {
|
if (self.error) {
|
||||||
if (failure) {
|
[self dispatchFailureBlock:failure error:self.error];
|
||||||
dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
|
||||||
failure(self, self.error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (success) {
|
[self dispatchSuccessBlock:success responseObject:self.responseImage];
|
||||||
dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{
|
|
||||||
success(self, self.responseImage);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -134,17 +134,9 @@ static dispatch_queue_t json_request_operation_processing_queue() {
|
||||||
id JSON = self.responseJSON;
|
id JSON = self.responseJSON;
|
||||||
|
|
||||||
if (self.JSONError) {
|
if (self.JSONError) {
|
||||||
if (failure) {
|
[self dispatchFailureBlock:failure error:self.JSONError];
|
||||||
dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
|
||||||
failure(self, self.JSONError);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (success) {
|
[self dispatchSuccessBlock:success responseObject:JSON];
|
||||||
dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{
|
|
||||||
success(self, JSON);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -124,26 +124,16 @@ static dispatch_queue_t property_list_request_operation_processing_queue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.error) {
|
if (self.error) {
|
||||||
if (failure) {
|
[self dispatchFailureBlock:failure error:self.error];
|
||||||
dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
|
||||||
failure(self, self.error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
dispatch_async(property_list_request_operation_processing_queue(), ^(void) {
|
dispatch_async(property_list_request_operation_processing_queue(), ^(void) {
|
||||||
id propertyList = self.responsePropertyList;
|
id propertyList = self.responsePropertyList;
|
||||||
|
|
||||||
dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{
|
|
||||||
if (self.propertyListError) {
|
if (self.propertyListError) {
|
||||||
if (failure) {
|
[self dispatchFailureBlock:failure error:self.propertyListError];
|
||||||
failure(self, self.propertyListError);
|
|
||||||
}
|
|
||||||
}else {
|
}else {
|
||||||
if (success) {
|
[self dispatchSuccessBlock:success responseObject:propertyList];
|
||||||
success(self, propertyList);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -187,17 +187,9 @@ static dispatch_queue_t xml_request_operation_processing_queue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.error) {
|
if (self.error) {
|
||||||
if (failure) {
|
[self dispatchFailureBlock:failure error:self.error];
|
||||||
dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
|
||||||
failure(self, self.error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (success) {
|
[self dispatchSuccessBlock:success responseObject:self.responseXMLParser];
|
||||||
dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{
|
|
||||||
success(self, self.responseXMLParser);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue