Search code examples
iosobjective-cafnetworking-2nsfilemanager

Download big file


I have a problem regarding the best approach to make an App that has to download and show pdf's, It is fed by a JSON that has links to 147 pdf files, sized between 1 and 2 MB.

Questions:

What is the best approach to download all the files to an iPad?

Shall I use AFNetworking 2.0?

Is NSFileManager the way to save all the files?

Problems I may encounter:

With an asynchronous download, if lost connection or no more space on the iPad, what are the counter mesures?

Are there tutorials or examples that deal with this situation?

Sorry for all the questions but I'm new to this. Best Regards.


Solution

  • What is the best approach to download all the files to an iPad?

    This is really broad as @rmaddy suggested. Specific questions are more easily answered. There are lots of ways you could download a file via an HTTP request to your device each with pros/cons depending on your situation.

    Shall I use AFNetworking 2.0?

    Sure. You'll get no argument from me. This is a widely used and solid API to interface with HTTP-based resources.

    Is NSFileManager the way to save all the files?

    Yes. NSFileManager is the class you use to read/write files from/to your app's sandbox.

    With an asynchronous download, if lost connection or no more space on the iPad, what are the counter measures?

    I'm not 100% certain so I can't speak to exactly what happens in this case. AFNetworking may provide some help by writing to a temporary file during a download, etc....

    Are there tutorials or examples that deal with this situation?

    I have a sample project on Github that shows a table of files that you can download. You can watch the progress of your downloads, pause each request, resume and cancel as well. When you're done you can view the file you downloaded. It uses AFNetworking and might be useful to you:

    https://github.com/chefnobody/StreamingDownloadTest