We are using the WKWebView for our Net page display frame,even if I set the NSURLRequest cache policy ,when it jumping ,the NSURLRequest cache policy still default to 0,how can I fix that problem?
NSURLRequest * urlReuqest = [[NSURLRequest alloc]initWithURL:url cachePolicy:1 timeoutInterval:30.0f]; //Before request, I set the NSURLRequest cachePolicy To 1 if(iOS8){ [(WKWebView *)_realWebView loadRequest:urlReuqest]; }
when I load the page, I catch the NSURLRequest cachePolicy in WKNavigationDelegate method implement
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{ NSLog(@"requestCachePolicy:%lu",(unsigned long)navigationAction.request.cachePolicy); decisionHandler(0); }
and the console shows requestCachePolicy:1,as I set before
however ,When I click on a link and jump to another net page,I catch the cachePolicy in the same WKNavigationDelegate method
the console shows requestCachePolicy:0 ,the cachePolicy is turn to default cachePolicy but not I set up before
How to change the WKWebview request cachePolicy When the net page jump?
How to change the WKWebview request cachePolicy When the net page jump?
AFAIK there’s no way to set the cache policy for every request generated by the web view; you didn’t mention it here, but AJAX requests (
XMLHttpRequest
) are also a concern. The web views
will honour cache policy headers returned by the server, and that’s the best way to resolve this issue IMO.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"