views:

553

answers:

2

Hey Guys,

I want to use the ASIHttprequest library to download some files, I am testing with their code and it is not working while the same code works on their sample

this is my code to call their view

QueueViewController *queueViewController = [[QueueViewController alloc] initWithNibName:@"Queue" bundle:nil]; [self.view addSubview:queueViewController.view];

This the code to make the request

- (IBAction)fetchThreeImages:(id)sender
{
    [imageView1 setImage:nil];
    [imageView2 setImage:nil];
    [imageView3 setImage:nil];

    [networkQueue cancelAllOperations];
    [networkQueue setDownloadProgressDelegate:progressIndicator];
    [networkQueue setRequestDidFinishSelector:@selector(imageFetchComplete:)];
    [networkQueue setShowAccurateProgress:[accurateProgress isOn]];
    [networkQueue setDelegate:self];

    ASIHTTPRequest *request;
    request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/i/logo.png"]] autorelease];
    [networkQueue addOperation:request];

    request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/i/trailsnetwork.png"]] autorelease];
    [networkQueue addOperation:request];

    request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/i/sharedspace20.png"]] autorelease];
    [networkQueue addOperation:request];

    [networkQueue go];

}


- (void)imageFetchComplete:(ASIHTTPRequest *)request
{
    UIImage *img = [UIImage imageWithData:[request responseData]];
    if (img) {
     if ([imageView1 image]) {
      if ([imageView2 image]) {
       [imageView3 setImage:img];
      } else {
       [imageView2 setImage:img];
      }
     } else {
      [imageView1 setImage:img];
     }
    }
}

It looks like the queue is being setup properly but imageFetchComplete method is not being called when the download is done.

A: 

Try setting requestDidFailSelector on your instance of ASINetworkQueue, as well as setting didFinishSelector and didFailSelector on each instance of ASIHTTPRequest. Call NSLog() from each of those callback methods in your delegate to see what's happening.

Note that by enabling showAccurateProgress on your ASINetworkQueue, an additional HEAD request is done for every request that the queue processes. This can sometimes be less than ideal in a mobile context.

Nathan de Vries
+1  A: 

I got the issue fixed, the problem was that I was not alloc networkQueue.

I was alloc networkQueue in the awakefromnib it wasn't being called. So I alloc networkQueue in the button click method. That fixEd the issue.

harekam_taj