3

I'm trying to find a way to get a UIWebView to cache an entire web page while one wifi and view it from the cache while connected to 3G, but then reload and recache while on WiFi again.

Are the any APIs or anything to do this?

Cheers

Chris Byatt
  • 3,689
  • 3
  • 34
  • 61

1 Answers1

3

regardless of 3G or WIFI you can use NSURLRequestReturnCacheDataElseLoad with your NSURLRequest which caches webpage otherwise load.. you could create a check for your 3G status

here is the usage of NSURLRequestReturnCacheDataElseLoad

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval: 10.0]; 

and load your data returned from webpage by using loadHTMLString in UIWebView

nsgulliver
  • 12,655
  • 23
  • 43
  • 64
  • Will this follow links through as well? Or just the initial page? – Chris Byatt Feb 26 '13 at 15:12
  • I think if you have loaded your pages once in the UiWebView and then try to load again, then it will show the cached pages, thus reducing the request time for loading the page from start.. you could follow this [question](http://stackoverflow.com/questions/1348696/how-to-cache-content-in-uiwebview-for-faster-loading-later-on), there could be more elaboration to the solution, you could save the page in your docs also to check for the connection – nsgulliver Feb 26 '13 at 15:24