Caching UIWebview from local loaded files - iphone

I have a uiwebview which loads documents from local file system. Some of the images on these HTML files are 2 mb. I wanted to cache those images or the whole HTML.
What is the best way to accomplish or is this even something I should consider?
Thanks for all your help.

It sounds like your best option would be to cache the large images and put them in the bundle at compile time. You could then change the URL's to those large images in your HTML to file URL's pointing to the files in the bundle.

Related

How can I save a html file with external resources using AFNetworking?

I would like to save a .html webpage with AFNetworking, but would also like to save the resources (such as .css files, .js files, images etc) within the webpage so that the whole webpage can be viewed offline.
Is this possible with AFNetworking, and how would I do it? Could a short example be posted please?
Thanks!
AFNetworking is not necessary to do this. Instead, what you want to do is use an NSURLCache subclass that supports disk cacheing (such as Peter Steinberger's fork of SDURLCache). With that in place, just load up a URL using a UIWebView (this may not necessarily have to be displayed to a user), and subsequent loads should use that local cache.
At the very least, do not waste your time trying to write something on your own to download assets on a webpage. This process requires a web browser (which UIWebView qualifies as) to determine everything needed to load.

downloading big size(In MB) .txt files using NSURLConnection

I'm downloading .txt files using NSURLConnection. Small size (in KB's) files are downloading perfectly but when i downloading big size(In MB) file, it always downloaded with corrupt data.
Sometimes big size .txt files are downloaded. But when i fetch those .txt file programmatically, it shows null content in it.
Please help.....
Thanks in advance.
You should check out the ASIHTTPRequest wrapper classes for HTTP request. They make the download of big sized files easy as they allow to download the files directly to the file system. I am currently using these wrapper classes on a project and I can assure you that they make your life a lot easier.

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!
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"];

Reading pdf file in ipad application

In my Ipad application i need to read .pdf files. these pdf files are stored in my server. the size of the pdf files are nearly 20Mb. Normaly in ipad we can view the pdf using UIwebview, but it's not useful in this case. the reason is normaly in iPad the pdf files are downloaded and showed in UIWebview.. but in my case the size maters..so i need another solution to read pdf files.
my suggestion is take the pdf in a spitted fashion.means suppose ur pdf contains 1000 pages download first page and load on the webView and start download for the remaining pages in the background something like nsoperationquee .so you need to modify in the server side also if you like my suggestion.
You have pdf url that in server right? get the pdf files from the server and store it locally like DB. After that you can display the PDF files from the DB. This is the one time process.Then it not take much time for download.
Or you get the pdf images and display in the uiimageview its simple and easy. But one drawback is you can read the text but not do any action on that i.e., copy the text like that
Thanking you

Cocoahttpserver serving images from iPhone App Bundle

I am having trouble getting Cocoahttpserver from Duesty Designs (awesome open source library makers of CocoaAsyncSocket) to serve images from my app bundle. Using the example iPhone project I can serve up an html file from the Resources dir in my project, but images refernced like:
<img src='foo.png' />
are not rendered.
Does anyone know why or what I need to do to make this work?
PNG images in your Resources directory are encoded in a funky format. modmyi has a good article on the subject.
My approach would probably be to name them with .png_unconverted, and rewrite the code in Cocoahttpserver to translate requests for .png into .png_unconverted.
Another solution would be to investigate the CopyPNGFile rule in the build system and see if you can get it to knock it off with the converting (this will probably make it impossible to render the PNG from within your app, however).
Finally, you could switch to JPEG. I don't believe that these files get modified.