开发者

Retain thread to listen delegate methods

开发者 https://www.devze.com 2023-03-29 00:12 出处:网络
I detach a NSThread say \"thread2\" and then call the NSUrlConnection class to get an xml from the remote server. Even it is not useful but i want to do that.

I detach a NSThread say "thread2" and then call the NSUrlConnection class to get an xml from the remote server. Even it is not useful but i want to do that.

Now my problem is the thread2 does wait for the delegate methods response. I want that delegate methods should be called on that thread2 and thread wait for the response.

Is it possibl开发者_如何学编程e or not. If yes then how.


You can use the synchronous method like so (assume you are dispatching the new thread to this method, or wrap this in a GCD call to a global queue):

- (void)threadDispatchMethod
{
  NSError* error = nil;
  NSData* result = nil;
  NSURLResponse* response = nil;
  result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
  if( result ) {
    // do wonderful things
  } else {
    // cry :'(
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消