My app has to do a series of uploads, depending by user’s actions. He can program a long list of uploads in a row, so I prefer that only one NSURLConnection is executed per time, to avoid network congestions. I’m using a NSOperationQueue to add the upload jobs; inside the queue I use:
[NSURLConnection sendAsynchronousRequest:uploadRequest
queue:tempQueue
completionHandler:/* completion code */];
My problem is that, even everything works, the function with the asynchronous connection returns immediately because the use of blocks, so the NSOperationQueue doesn’t wait for the NSURLConnection to finish and it directly continues to the next upload.
I know I can implement -for example- a NSMutableArray to track the list of current and pending uploads and dispatch them accordingly, but I’d like to know if there’s a simple way to tell this loop to wait if there’s already a opened NSURLConnection in progress.
Why not use a synchronous connection?
Then you set the maximum number of concurrent operations to 1 and the uploads should go one by one.