Solved

Dispatch several download tasks

Posted on 2014-12-18
1
177 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
View container field on iPad with filemaker go 3 39
iOS application authentication 7 42
Unit test ionic mobile app for iPad 2 119
Connecting database in Xamarin? 6 54
     Intro      In this article, I will show you how to parse a JSON in Swift using an open source library called SwiftyJSON (https://github.com/SwiftyJSON/SwiftyJSON). If you haven't heard of a JSON before, it stands for JavaScript Object Notation…
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.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now