Solved

Dispatch several download tasks

Posted on 2014-12-18
1
182 Views
Last Modified: 2015-01-05
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:
-(void)startAllDownloads{

    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]];
            }
            else{

                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 :)
0
Comment
Question by:claire89
1 Comment
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 500 total points
ID: 40508579
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
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iOS 9 and TouchID 3 113
iOS: Firing a segue programmatically 7 167
Allow iPhone user to edit Office 365 shared calendar from iPhone 4 56
iOS and Managed domains 2 86
There is a security feature on iOS devices that is nearly impenetrable when it has been activated.  This article will provide some possible solutions as well as necessary steps to take to ensure you do not end up with a locked device.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question