I've been testing an iPhone view controller that uses a UIWebView to load external content, as opposed to resources in the project's bundle. Another engineer noticed that the web view wasn't caching at all, so I went into do some research. Some older questions indicated that UIWebView's just couldn't cache external content.
Previous SO Questions on UIWebView caching:
- Is it possible to cache resources loaded in an iPhone UIWebView?
- Is it possible to cache web pages with a UIWebView?
- Reading HTML content from a UIWebView
Those posts were pretty deflating, but I noticed that they were all asked before iOS 4.0 came out. I tested the following approach for caching, which seemed pretty straight-forward.
NSURLRequest *request = [NSURLRequest requestWithURL:myUrl
cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];
[webView loadRequest:request];
This seems to work great on iOS 4.3 but doesn't work at all on iOS 3.0. I tested this by pointing the devices to a Charles proxy (on iPhone, Settings -> WiFi, Manual proxy) and recording the traffic to my server.
Did the UIWebView start observing the cache policy in iOS 4.0? Can anyone else confirm this or am I just imagining things?
[NSURLRequest requestWithURL:myUrl]
and it seemed to load from the cache – goldierox