diff --git a/AFNetworking/AFImageRequestOperation.m b/AFNetworking/AFImageRequestOperation.m index f0c7b59..b4c2907 100644 --- a/AFNetworking/AFImageRequestOperation.m +++ b/AFNetworking/AFImageRequestOperation.m @@ -33,6 +33,15 @@ static inline CGSize kAFImageRequestRoundedCornerRadii(CGSize imageSize) { return CGSizeMake(dimension, dimension); } +static dispatch_queue_t af_image_request_operation_processing_queue; +static dispatch_queue_t image_request_operation_processing_queue() { + if (af_image_request_operation_processing_queue == NULL) { + af_image_request_operation_processing_queue = dispatch_queue_create("com.alamofire.image-request.processing", 0); + } + + return af_image_request_operation_processing_queue; +} + @implementation AFImageRequestOperation + (id)operationWithRequest:(NSURLRequest *)urlRequest @@ -47,7 +56,7 @@ static inline CGSize kAFImageRequestRoundedCornerRadii(CGSize imageSize) { success:(void (^)(UIImage *image))success { return [self operationWithRequest:urlRequest completion:^(NSURLRequest *request, NSHTTPURLResponse *response, NSData *data, NSError *error) { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { + dispatch_async(image_request_operation_processing_queue(), ^(void) { UIImage *image = nil; if ([[UIScreen mainScreen] scale] == 2.0) { CGImageRef imageRef = [[UIImage imageWithData:data] CGImage]; diff --git a/AFNetworking/AFJSONRequestOperation.m b/AFNetworking/AFJSONRequestOperation.m index 66f195a..6b4a59a 100644 --- a/AFNetworking/AFJSONRequestOperation.m +++ b/AFNetworking/AFJSONRequestOperation.m @@ -25,6 +25,15 @@ #include +static dispatch_queue_t af_json_request_operation_processing_queue; +static dispatch_queue_t json_request_operation_processing_queue() { + if (af_json_request_operation_processing_queue == NULL) { + af_json_request_operation_processing_queue = dispatch_queue_create("com.alamofire.json-request.processing", 0); + } + + return af_json_request_operation_processing_queue; +} + @implementation AFJSONRequestOperation + (id)operationWithRequest:(NSURLRequest *)urlRequest @@ -62,23 +71,23 @@ failure(error); } } else { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { + dispatch_async(json_request_operation_processing_queue(), ^(void) { id JSON = nil; - + NSError *JSONError = nil; #if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_3 if ([NSJSONSerialization class]) { - JSON = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; + JSON = [NSJSONSerialization JSONObjectWithData:data options:0 error:&JSONError]; } else { - JSON = [[JSONDecoder decoder] objectWithData:data error:&error]; + JSON = [[JSONDecoder decoder] objectWithData:data error:&JSONError]; } #else - JSON = [[JSONDecoder decoder] objectWithData:data error:&error]; + JSON = [[JSONDecoder decoder] objectWithData:data error:&JSONError]; #endif dispatch_sync(dispatch_get_main_queue(), ^(void) { - if (error) { + if (JSONError) { if (failure) { - failure(error); + failure(JSONError); } } else { if (success) {