Bruno
Bruno

Reputation: 1032

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.

Upvotes: 1

Views: 586

Answers (2)

Rob
Rob

Reputation: 437392

When downloading large files, the main counsel would be to avoid trying to load these into memory as you download them. Instead, make sure you stream them directly to persistent storage. In terms of handling space-specific errors, just make sure you check NSError objects that are returned to you in completion handlers or the appropriate delegate methods.

Either way, you avoid some of the memory consumption challenges associated with downloading large files.

Upvotes: 1

Aaron
Aaron

Reputation: 7145

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

Upvotes: 1

Related Questions