?
Solved

Dispatch several download tasks

Posted on 2014-12-18
1
Medium Priority
?
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 1500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

What's a UDID? If you're involved in developing, testing, or even reviewing an iOS application that's in beta, then at some point you may need to know the UDID for any iOS devices that you'll be testing on. What's the UDID? It stands for Unique Dev…
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

762 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