I'm a bit confused about GCD
I try caling a class where my webservice call is executed:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[searchService doSearch:self.searchData];
});
I'm using Sudzc-generated webservice. The actual service call to the service generated with Sudzc and is inside the SearchService class is the following:
[service doSearch:self action:@selector(doSearchHandler:) e: searchArgs];
Once the call is done I should return to:
- (void) doSearchHandler: (id) value {
}
Without using the GCD it works fine, but when I add it, I never return to the doSearchHandler method.
I had the problem of the Sudzc operation blocking the main thread.
However, the Soap request is not the problem as, although the NSURLRequest is executed on the main thread, its data is managed by the delegate didReceiveData
What was blocking my UI was the processing of the received XML that happened in the Handler method.
In the handler method (- (void) SudzcRequestHandler: (id) value { ...
) I process the data like this:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
...processing...
[[NSNotificationCenter defaultCenter] postNotificationName:KManagerHasFinishedLoading object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:NOTIFICATION_RESULT_OK], @"Result", nil]];
});
I run the processing in Manager, which is a singleton object, but other implementations may vary. So the notification is used to let my ViewController know that processing has ended.
You should look into the Sync-Async pattern. The two links from the answer of this SO will help. It doesn't use GCD directly. But you can adapt easily.