• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

Dispatch several download tasks

I'm building an iOS app that will download 300 pdf files each one with more or less 3mb in size and I have limited understanding of Grand Central Dispatch.

I came across a really nice tutorial with code that I'm using:
Tutorial:Guide link
Code:Code example

The problem is  that the app will freeze for some time, when running this code to add all the 300 tasks:

    for (int i=0; i<[self.arrFileDownloadData count]; i++) {
        FileDownloadInfo *fdi = [self.arrFileDownloadData objectAtIndex:i];

        // Check if a file is already being downloaded or not.

        if (!fdi.isDownloading) {

            // Check if should create a new download task using a URL, or using resume data.
            if (fdi.taskIdentifier == -1) {
                //new NSURLSessionDownloadTask
                fdi.downloadTask = [self.session downloadTaskWithURL:[NSURL URLWithString:fdi.downloadSource]];

                fdi.downloadTask = [self.session downloadTaskWithResumeData:fdi.taskResumeData];


            // Keep the new taskIdentifier.
            fdi.taskIdentifier = fdi.downloadTask.taskIdentifier;

            NSLog(@"starting download id:%lu",fdi.taskIdentifier);

            // Start the download.
            //dispatch_async(dispatch_get_main_queue(), ^{
            [fdi.downloadTask resume];

            // Indicate for each file that is being downloaded.
            fdi.isDownloading = YES;

Open in new window

I have tried with a dispatch_async but with no success,  It always freezes.

Sorry if I'm not being very clear, If more info is needed just ask :)
1 Solution
You didn't show the session configuration. Probably, you have something like:
config.HTTPMaximumConnectionsPerHost = 3;

Open in new window

Or even with the timeouts:
config.timeoutIntervalForResource = 120;
config.timeoutIntervalForRequest = 120;

Open in new window

WWDC2013. What's New in Foundation Networking. 705
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now