I'm tinkering with adding a model layer to an iPhone application so that I can serialize/prioritize HTTP requests and selectively cache responses. Thanks to UIWebViewDelegate, the following method makes this fairly straight forward (in theory):
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
Basically, my code inspects the navigationType, sends the request off to the model, and returns NO. In turn, the model layer handles the request and, when complete, stuffs the data back into the UIWebView using:
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)baseURL
Unfortunately, when pushing data back into the UIWebView, I often see shouldStartLoadWithRequest triggered again (this time with a navigationType of 5, but using the same URL as the original request). I cannot rely on the model to serve this from the cache (as the URL is identical to before), so I've got to have the UIWebView handle it itself by returning YES.
I'd like to avoid this such that the model (and caching layer) see and handle all requests. Does anyone have any ideas why I'm seeing a navigationType of 5 in a secondary shouldStartLoadWithRequest?