• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Asynchronous downloading again
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Asynchronous downloading again


  • Subject: Re: Asynchronous downloading again
  • From: Roland King <email@hidden>
  • Date: Sun, 1 Nov 2009 10:22:22 +0800

So you've used the observation that your user interface element is animating a spin to decide that mixing synchronous and asynchronous calls is somehow causing things to happen on different threads; you're programming backwards. Also what you're doing here is making your app as slow as it can possibly be by ensuring your two files are downloaded serially instead of potentially at the same time, and as complicated as it can possibly be because you've mixed two different ways of accomplishing the same thing.

You can trivially use one delegate to manage both these downloads, have them happen at the same time and only call downloadFinished when both of them have finished, or if you have more than 2, all 3, or 4 or 127 of them.

On 01-Nov-2009, at 9:50 AM, DKJ wrote:

All of the files have to be downloaded before the app can do anything. I get the connectionDidFinishLoading delegate method of my one and only NSURLConnection to call a downloadFinished method at the end of the synchronous downloads, so the app knows everything is in place and can start processing the files.

I was worried that having a download connection for each file would make it more complicated for the app to know when they were all finished.

And the main thread doesn't seem to be blocked, because my activity indicator is now spinning quite nicely during the download.


On 2009-10-31, at 18:02 , Roland King wrote:

The whole point of doing things asynchronously is you don't have to care about waiting for one thing to do another thing, just set up two NSURLConnections and start them going at the same time. So unless you need some information from file 1 before starting on file 2

connection1 = [ [ NSURLConnection alloc ] initWithRequest:request1 delegate:self ];
connection2 = [ [ NSURLConnection alloc ] initWithRequest:request2 delegate:self ];


where connection1 and connection2 are instance variables of your class. Then when you get the callbacks in your delegate just look to see which connection they are for and deal with them appropriately. When they are both finished downloading (and don't forget to release the NSURLConnection(s) when they are) you start doing whatever else it is you want to do.

Don't understand why you keep trying to go back to synchronous downloads and you're talking about threads, who says NSURLConnection uses threads at all. Apart from that, if you read the documentation for NSURLConnection it tells you all delegate calls take place on the thread you initiated the download on so, no, even if you did what you suggested you'd just block the main thread with the download of file2.

===================== Hatzic Intellectual Software Victoria BC, Canada www.hatzicware.com





_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Asynchronous downloading again
      • From: DKJ <email@hidden>
References: 
 >Asynchronous downloading again (From: DKJ <email@hidden>)
 >Re: Asynchronous downloading again (From: Roland King <email@hidden>)
 >Re: Asynchronous downloading again (From: DKJ <email@hidden>)

  • Prev by Date: Re: Asynchronous downloading again
  • Next by Date: Re: Asynchronous downloading again
  • Previous by thread: Re: Asynchronous downloading again
  • Next by thread: Re: Asynchronous downloading again
  • Index(es):
    • Date
    • Thread