Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top