I am making an iPad app where you can download files (like PDF, doc, etc) and view them offline.
I already have the view part and you can download a file to the document directory.
As it is now you need to wait for the download to be finished to move on.
This can be solved by putting it in a thread, but what happens when the user downloads multiple files or even download the same file multiple times?
My idea is to make a download queue, with a view for the progress.
Workflow:
-
The user opens a document and press download, the user gets a message that the download is started and can be viewed in the offline documents view.
-
The user downloads 3 more documents.
-
When the user goes to the offline document view the user sees a table view with 4 filled cells. 2 documents are done loading and 2 other are still downloading because there is a download/status bar shown in the table view cell.
-
The downloaded documents can be viewed or deleted.
-
The downloads in progress can not be watched (yet) but can be cancelled.
I want to make a threaded download class where you can add urls to be downloaded. the class has methods to cancel and delete document-downloads, but also has methods to return the progress.
If possible the class can handle simultaneous downloads.
The problem is, I don’t know where to start?
NSURLConnectionis already asynchronous. All you need to do is to createNSURLConnectioninstances, associate them with your data structures, and have at it.Here’s an example where I assume you have one UIView per item. If you use a table view you can’t count on view instances, but instead associate a download with an NSIndexPath, or something else.
Then implement the other NSURLConnection delegate methods to do what you need.