Solved

Dispatch several download tasks

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Ever wanted to watch videos in your computer from the bed without the need of standing up and shutting down the computer?  Is your computers operating system Windows XP, Windows Vista or Windows 7?  Do you own a iOS device? If all the answers were y…
I recently went through the process of creating an installable image of an iPhone mobile app (an .ipa file) that beta testers could load onto their test devices. The process involved quite a few steps, but both Appcelerator and Diawi.org had decent …
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

12 Experts available now in Live!

Get 1:1 Help Now