Performning sudzc webservice using GCD

寵の児 提交于 2020-01-06 20:01:16

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/11359493/performning-sudzc-webservice-using-gcd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!