Testing Async downloads with ASIHTTPRequest

Posted by Baishampayan Ghose on Stack Overflow See other posts from Stack Overflow or by Baishampayan Ghose
Published on 2010-05-25T07:09:42Z Indexed on 2010/05/25 7:11 UTC
Read the original article Hit count: 283

I am writing a simple library using ASIHTTPRequest where I am fetching URLs in an async manner. My problem is that the main function that I have written to test my lib exits before the async calls are finished.

I am very new to Obj C and iPhone development, can anyone suggest a good way to wait before all the requests are finished in the main function?

Currently, my main function looks like this -

int main(int argc, char *argv[]) {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  IBGApp *ibgapp = [[IBGApp alloc] init];
  IBGLib *ibgl = [[IBGLib alloc] initWithUsername:@"joe" andPassword:@"xxx"];

  // The two method calls below download URLs async.
  [ibgl downloadURL:@"http://yahoo.com/" withRequestDelegate:ibgapp andRequestSelector:@selector(logData:)];
  [ibgl downloadURL:@"http://google.com/" withRequestDelegate:ibgapp andRequestSelector:@selector(logData:)];

  [pool release];
  return 0; // I reach here before the async calls are done.
}

So what is the best way to wait till the async calls are done? I tried putting sleep, but obviously doesn't work.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c