1

I have an app where i am trying to download files like images/videos from an URL. At present i am using grand central dispatch to establish a async NSURL connection on my main thread so it do

=

lost found
  • 329
  • 1
  • 3
  • 12

3 Answers3

0

Instead of asynchronous NSURConnections on the main thread, run synchronous NSURLConnections on a background thread. I suggest creating an NSOperationQueue instead of using GCD directly, as it is easier. Queue up your requests using -addOperationWithBlock: or by creating NSOperation subclasses. Unless you specify otherwise, they will run only one at a time.

Brendon
  • 882
  • 6
  • 12
0

AFNetworking is a beautiful library that does most of what you want. here You will just need to

1) Initialise a main queue (NSOPerationqueue), and set its max concurrent operation to the value you want. With 2, I'm fine, and the app is very responsive (downloads plenty of images from flickr.

2) configure your memory cache NSURLCache to an appropriate value - needs some tests to fit your app usage-

3) When you download an image or video, decide which cache policy should apply to the URLRequest (use cache, ignore cache etc...) beware that some servers don't send cache info headers so revalidation may always happen unless you manually check the cache content, and extract the image (in that case, display is very very fast). Revalidation can take time if you have plenty of images.

4) Access this queue via a standard singleton.

5) enqueue your operations to that queue.

This has a low memory foot print, and works really great.

et voila !

NOTE: are you cleaning [downloadArray addObject:imageObject]; at some point ? NOTE: didn't read properly, but for you case you might want to set max operation to 1

Alex
  • 1,581
  • 1
  • 11
  • 27
  • thanks for your reply. I am not caching the images at present my concern is downloading large videos. Will AFNetworking help my need of downloading files in a serial queue and not open up a bunch of NSURLConnections. I ll definitely look into it. – lost found May 09 '13 at 01:27
  • Yes i have thought about cleaning the up the array but i am not yet decided at what point – lost found May 09 '13 at 01:29
  • video streaming is somewhat different from downloading a video, so you might need to look into apple's doc https://developer.apple.com/resources/http-streaming/ – Alex May 09 '13 at 09:53
0

try my answer :

If You want to download more then one file then you have to use HCDownloadViewController because it create queue for downloading. see my answer at below link.

iOS NSURLConnection not downloading files from certain URLs

Community
  • 1
  • 1
SAMIR RATHOD
  • 3,512
  • 1
  • 20
  • 45