From 9a78cc54cd47cee8fd3759d3bb6309318af7a871 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 21 Sep 2011 16:07:25 -0500 Subject: [PATCH] Dispatching callbacks to main thread for JSON requests --- AFNetworking/AFJSONRequestOperation.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/AFNetworking/AFJSONRequestOperation.m b/AFNetworking/AFJSONRequestOperation.m index c855ebe..9e8e443 100644 --- a/AFNetworking/AFJSONRequestOperation.m +++ b/AFNetworking/AFJSONRequestOperation.m @@ -84,11 +84,15 @@ static dispatch_queue_t json_request_operation_processing_queue() { if (error) { if (failure) { - failure(request, response, error); + dispatch_async(dispatch_get_main_queue(), ^{ + failure(request, response, error); + }); } } else if ([data length] == 0) { if (success) { - success(request, response, nil); + dispatch_async(dispatch_get_main_queue(), ^{ + success(request, response, nil); + }); } } else { dispatch_async(json_request_operation_processing_queue(), ^(void) { @@ -104,7 +108,7 @@ static dispatch_queue_t json_request_operation_processing_queue() { JSON = [[JSONDecoder decoder] objectWithData:data error:&JSONError]; #endif - dispatch_sync(dispatch_get_main_queue(), ^(void) { + dispatch_async(dispatch_get_main_queue(), ^(void) { if (JSONError) { if (failure) { failure(request, response, JSONError);