Iqbal Khan
Iqbal Khan

Reputation: 4617

Retain thread to listen delegate methods

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 possible or not. If yes then how.

Upvotes: 0

Views: 55

Answers (1)

Jason Coco
Jason Coco

Reputation: 78393

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 :'(
  }
}

Upvotes: 2

Related Questions