Quote:
Originally Posted by cityofangels
Thanks, but that example is very complicated. I simply want to load the downloading on the background thread so it doesn't slow down the UI.
|
Threads are resource hogs, and best avoided.
You are much better served to use NSURLConnection and NSURLRequest to create an async download on the same thread. It takes about a page of code to do. You create an NSURL for the remote file. You create an NSURLRequest that represents your request for a remote file. You create an NSURLConnection object to manage the connection to the remote host. You set yourself as the delegate of the NSURLConnection. You start the download running, and handle 2 or 3 delegate methods that notify you as data arrives, and when you get a message that all the data has been delivered, you save the data to disk.
Alternately, you can use the ASIHTTPRequest library to do this. I haven't used it before, but supposedly it makes doing async downloading a snap. (just a couple of lines of code.) Do a google on ASIHTTPRequest to find it.