It is a good practice to use requests asynchronously.
To find out if a request has finished or not, you could do this by simply conforming your class to the [ASIHTTPRequestDelegate][1]
.
It gives you a bunch of methods to implement for a successful, failed or a redirected request.
In the given case you're looking for
- (void)requestFinished:(ASIHTTPRequest *)request;
You would have to set the delegate of the request to the current calling class.
Depending on the result of your current request you may then fire another request. You could put an if-statement
in there to check the URL and the response code and fire your next request accordingly. (There are many other ways to determine when you could call the next request. But the easiest would be to listen to the result of the first request.)
Here's a bit of code from the ASIHTTPRequest Projects Documentation:
- (IBAction)grabURLInBackground:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
}
HTH