Adding a model layer (with caching) for UIWebViews; problem with UIWebViewNavigationType and shouldStartLoadWithRequest

I was messing around with adding a model layer to the iPhone application so that I could serialize / prioritize HTTP requests and selectively cache responses. Thanks to the UIWebViewDelegate, the following method makes it pretty straightforward (theoretically):

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

Basically, my code checks the type of navigationType, sends a request to the model and returns NO. In turn, the model layer processes the request and, when it is completed, returns data to the UIWebView using:

- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)baseURL

Unfortunately, when I click the data back into the UIWebView, I often see that shouldStartLoadWithRequest starts up again (this time with type navigation 5, but using the same URL as the original request). I cannot rely on a model to service this from the cache (since the URL is identical to the previous one), so I need the UIWebView to process it myself, returning YES.

I would like to avoid this so that the model (and the cache level) would look through and process all requests. Does anyone have any ideas why I see navigationType of 5 in the secondary ifStartLoadWithRequest?

+3
source share
1 answer

, , , .

, , - UIWebViewNavigationTypeOther. , navigationType , , loadData: MIMEType: textEncodingName: baseURL. .

, 100% . webView: ShouldStartLoadWithRequest: navigationType: , loadData: MIMEType: textEncodingName: baseURL, , BOOL, , loadCachedData, YES , webView: ShouldStartLoadWithRequest: navigationType: . , . . .

+4

Source: https://habr.com/ru/post/1716021/


All Articles