views:

754

answers:

1

Hi,

I use ASINetworkQueue to send two requests, which are in a queue. My problem is, that I'm not able to receive notifications when a request fails/is done.

Code:

    [networkQueue cancelAllOperations];
 [networkQueue setShowAccurateProgress:YES];
 [networkQueue setUploadProgressDelegate:self.progressIndicator];
 [networkQueue setDelegate:self];
 [networkQueue setQueueDidFinishSelector:@selector(queueDidFinish)];


 NSURL *urlAttachment = [NSURL URLWithString:@"http://localhost/test1.xml"]];
 ASIFormDataRequest *requestFile = [[[ASIFormDataRequest alloc] initWithURL:urlAttachment] autorelease];
 [requestFile setFile:filePath forKey:@"attachment[test]"];
 [requestFile setDidFailSelector:@selector(test1WentWrong)];
 [requestFile setDidFinishSelector:@selector(test1Done)];
 [networkQueue addOperation:requestFile]; //queue is an NSOperationQueue

 NSURL *url = [NSURL URLWithString:@"http://localhost/test2.xml"]];
 ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
 [request setPostValue:test.filename forKey:@"filename[test]" ];
 [request setDidFailSelector:@selector(test2WentWrong)];
 [request setDidFinishSelector:@selector(test2Done)];
 [networkQueue addOperation:request]; //queue is an NSOperationQueue

 [networkQueue go];

test1WentWrong, test1Done, test2WentWrong, test2Done aren't called. Although the request runs fine and queueDidFinish gets called.

+3  A: 

Hi Stefan

You need to set the delegate of the individual requests rather than the queue.

Basically, if you set the didFinish and didFail selectors on the queue, the queue's delegate is called. If you set them on the request, the request's delegate is called (You can also do both, in which case both get called).

In your case, where you want to use the same delegate for both requests, but different selectors for didFail / didFinish, I can see it would make sense for the queue's delegate to be called if you didn't set a delegate for the request. Perhaps I should add this... :)

Ben

pokeb
Ben, thank you very much for your answer. I was blind ;-) Adding the delegate worked perfectly. Thank you for such a great wrapper like ASIHTTPRequest. It's very nice and handy to use. I like it.
Stefan