Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView webpage caching for offline viewing

Tags:

First of all, I'm pretty sure that I have checked every answer here and nothing does what I would like to do.

  1. In this question, for answer is given ASIHTTPRequest which is dead project. (How do I download an entire webpage (with images) on the iPhone?)
  2. In this question, user proposed RNCachingURLProtocol which is really great but I had a few problems after closing app completely (closing it in task-bar). After that I didn't get css or images, only html was loaded. (Cache a single webpage for use when offline in Xcode / UIWEBVIEW).

There are few more answers but none is good. There must be some simple implementation for what I'm searching.

I would like to: When app opens, it loads some webpage. I want to save that webpage completely. Now user can quit or do whatever he wants (just not uninstall). As long as there is some internet connection (I check that using reachability class), webpage loads normally and it's being saved. IF USER opens app and there is NO INTERNET connection I just want to show message that "it might not be up to date bla bla boa" and show complete, saved webpage that was saved last time application has internet connection.

What would be the best way (up to date) to save complete webpage. I'v found something about MKNetworkKit but I'm not sure how to use that. Any help would be appreciated.

like image 611
jovanjovanovic Avatar asked May 30 '13 02:05

jovanjovanovic


2 Answers

It sounds like the standard caching is not good enough because you have no control over what will be cached and for how long. The easiest way for solving this is by creating your own caching meganism by overriding the NSURLCache. You can find some documentation about that at http://nshipster.com/nsurlcache/ and a sample at http://github.com/evermeer/EVURLCache That sample even let you use a pre populated cache that can be included in your app install.

like image 175
Edwin Vermeer Avatar answered Oct 26 '22 05:10

Edwin Vermeer


NSString *stringurl=[NSString stringWithFormat:@"http://www.google.com"];
NSURL *url=[NSURL URLWithString:stringurl];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:15.0];
[uiwebview loadRequest:theRequest];

The URL loading system provides a composite on-disk and in-memory cache of responses to requests. This cache allows an application to reduce its dependency on a network connection and increase its performance.

like image 28
Rahul K Rajan Avatar answered Oct 26 '22 05:10

Rahul K Rajan