iphonepdfresourcesdownloadmainbundle

How can I save pdf's to my app resources folder, and access them in run-time?


I have an app I'm designing that will allow for lots of PDF viewing. There are a lot of different languages available, and so if I were to include all of them in the app, it would be like 100+ mb in size which just won't fly.

So I'm thinking that I am going to put the pdf's on my server, and access them with a direct download link like this:

http://mysite.com/pdfs/thepdf.pdf

Which will return the exact pdf I want. So I'm wondering how I can go about accessing these resources as I download them on the fly?

I imagine I need to save the pdf's to the app resources folder? And then when a tableView row for the pdf is selected, I check if the pdf is in the resources folder (how do I do that?), and if not, pull it down off the server, and load it into my view?

I think I have an okay idea of what I need to do, just not very clear on the code to do it. Can anybody post the code for accessing the resources folder (if that's actually what I need to be doing), and maybe the code for how to check if something is in the resources folder?

Thanks!


Solution

  • Have you considered using a UIWebView to view the PDF instead of downloading and loading it yourself? UIWebView should take care of caching, so you won't have to worry about that.

    Assuming that a UIWebView won't work, to download PDFs and see if they exist, you need to store it in the Documents folder. The resources folder cannot be altered after you submit your app to Apple, but the Documents folder in your app is completely fine. To access it, I would actually recommend ConciseKit, which can be found on GitHub. It gives you a helper method to access your app's document directory. The helper method is

    [$ documentPath];
    

    Then you can get the path for a file by doing

    [[$ documentPath] stringByAppendingPathComponent:@"file.pdf"];
    

    So that is how you get a path to a file, to check if it exists, you want to use NSFileManager.

    [[NSFileManager defaultManager] fileExistsAtPath:@"path from above"];