Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Cache Content from a UIWebView

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

like image 473
Chris Byatt Avatar asked Jul 12 '26 06:07

Chris Byatt


1 Answers

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

like image 95
nsgulliver Avatar answered Jul 14 '26 21:07

nsgulliver