Frage

How do you tell when a request is finished (using ASIHTTPRequest)? Here is the code I am using:

[request setDidFinishSelector:@selector(requestFinished:)];

...

-(void)requestFinished:(ASIHTTPRequest *)request {

    NSLog(@"The request is done.");

}

However, when request is done, "The request is done" is never printed to the log. Am I doing something wrong? Thanks.

War es hilfreich?

Lösung 2

I forgot to set the delegate to self. Oops!

[request setDelegate:self];

Andere Tipps

maybe your connection is failing? In this case, you should test for - (void)requestFailed:(ASIHTTPRequest *)request

Did you set the request delegate? Example code:

- (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];
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top