I start my ASIHTTPrequest synchronously in a separate thread like this :
//inside this start method I create my ASIHTTPRequest and start it
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[process start];
});
But the completionBlock is still fired on the main thread. Can one keep the execution of the completionBlock in the same thread as where the request was started?
The only thing i can come up with to solve this is to define a dispatch queue and manually execute the completionBlock in the same thread, thus holding a reference to a created queue. But that does not solve it directly because you would pass for a freaking little moment in the main thread before redirecting the rest of the code to the created dispatch queue.
Does someone have a better solution?
EDIT: The same is also true for AFNetworking completion blocks…
Ok, to answer my own question :
ASIHTTPRequest framework does not have an option to start completion blocks in a different thread.
Instead one can use the AFNetwork framework. Here you have two properties on any type of AFOperation called ‘successCallbackQueue‘ and ‘failureCallbackQueue‘. Where you can add a predefined ‘dispatch_queue_t‘ to handle the execution of success and failure blocks.
Hope this will help others with the same problem!
UPDATE : Example