Search code examples
iphonequeueasihttprequestnsoperationqueue

ASINetworkQueue setQueueDidFinishSelector selector ending prematurely ?


I've just started testing some upload utility i've built and put 47 items for upload, but the queue stops randomly at the 15th or 18th or 21st item, not sure exactly why, but the selector is being called too early while not all the requests are over.

Only thing i did which is special is raise the maxconcurrent requests to 6 instead of 4 , but that doesn't seem like a huge issue.

I'm configuring my selectors as follows:

[self.uploadQueue setDelegate: self];
[self.uploadQueue cancelAllOperations];
[self.uploadQueue setRequestDidStartSelector: @selector(uploadRequestStarted:)];
[self.uploadQueue setRequestDidFinishSelector:@selector(uploadRequestEnded:)];
[self.uploadQueue setQueueDidFinishSelector:@selector(uploadQueueEnded:)];
[self.uploadQueue setDownloadProgressDelegate: myProgress];
[self.uploadQueue showAccurateProgress];

Here is my log:

2011-08-18 12:39:03.916 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView startUpload] Num requests: 47
2011-08-18 12:39:08.987 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadRequestEnded:] Finished uploading photo #3 successfully!
2011-08-18 12:39:09.036 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadRequestEnded:] Finished uploading photo #2 successfully!
2011-08-18 12:39:09.911 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadRequestEnded:] Finished uploading photo #0 successfully!
2011-08-18 12:39:09.913 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadRequestEnded:] Finished uploading photo #5 successfully!
2011-08-18 12:39:10.011 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadRequestEnded:] Finished uploading photo #4 successfully!
2011-08-18 12:39:12.691 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadRequestEnded:] Finished uploading photo #6 successfully!
2011-08-18 12:39:13.588 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadRequestEnded:] Finished uploading photo #9 successfully!
2011-08-18 12:39:14.205 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadRequestEnded:] Finished uploading photo #8 successfully!
2011-08-18 12:39:14.229 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadRequestEnded:] Finished uploading photo #10 successfully!
2011-08-18 12:39:15.739 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadRequestEnded:] Finished uploading photo #11 successfully!
2011-08-18 12:39:17.278 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadRequestEnded:] Finished uploading photo #12 successfully!
2011-08-18 12:39:17.894 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadRequestEnded:] Finished uploading photo #13 successfully!
2011-08-18 12:39:18.815 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadRequestEnded:] Finished uploading photo #15 successfully!
2011-08-18 12:39:18.986 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadRequestEnded:] Finished uploading photo #14 successfully!
2011-08-18 12:39:19.191 MyTestApp[4240/0xacc992c0] [lvl=2] -[MyView uploadQueueEnded:] queue ended?

Would love to hear any of you suggestions :) Thanks in advance, Shai.


Solution

  • Have you tried setting setShouldCancelAllRequestsOnFailure: to NO ? The default behaviour of a queue is for it to cancel all remaining requests if any single request fails.

    It may be that a request is failing (for some reason) which is causing you queue to finish prematurely.