Handling sequential downloads with NSURLSession

I have a data fetch task that I want to do on a background thread, but you need to make additional calls after receiving a response in completionBlock

.

For example:

NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:requestURL completionHandler:completionBlock] resume];

      

After successfully completing the task and calls completionBlock

, I want to load, add 10 more resources from NSURL

which are part of the data completionBlock

.

Would it be better to call again dataTaskWithURL:completionHandler:

in the block per request, or do blocking network calls in a loop in completionBlock

?

Thank!

+3


source to share


1 answer


Yes, you can just make additional calls to completionBlock

. But the requests don't have to be "blocking", but rather you simply initiate additional asynchronous requests for additional data. You want them to run concurrently with each other if your model supports this. You pay a substantial penalty if you consistently submit these follow-up requests versus the concurrent one.



+1


source







All Articles