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.

On 01-Nov-2009, at 6:34 AM, DKJ wrote:

I've got a series of data files that my app needs to download before the user can do anything. Because I want to have an activity indicator spinning while the download is in progress, I have to do asynchronous downloading. (Thanks to the list members who guided me to that epiphany.) So I'm going to use the NSURLConnection class to do the download.

Now I'm wondering if this will work: Suppose I want to download file1 and file2. (Again, the user can do nothing until both files are downloaded.) I use NSURLConnection to download file1. Then in the connectionDidFinishLoading delegate method, I do a synchronous download of file2, with something like stringWithContentsOfURL.

My idea is that the synchronous download of file2 would be taking place in a separate thread from the one that started the asynchronous download of file1. So, from the first thread's point of view, file2 is being downloaded asynchronously too.

Am I on the right track here? If so, it sure would simplify downloading all those files.

dkj

P.S. It's time for my semi-anual global "Thank You" to all those list members who've responded to my queries over the last six months.

   THANK YOU!
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org

This email sent to r...@rols.org

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to