Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

WKWebView caching not working

$
0
0

Hi there,

I’m building a Xamarin Forms project whose main component is a WebView.
I have built it such that on iOS7 a UIWebView is used, and on iOS8 a WKWebView is used.

Basically I want a cache for the WebViews to persist between runs of the application.

iOS7
Using iOS7’s UIWebView I managed to figure it out using the code below:

NSUrlCache.SharedCache = new NSUrlCache(50 * 1024 * 1024, 200 * 1024 * 1024, "cache");
NSUrlCache.SharedCache.Init();

Now unfortunately I didn’t find any documentation explaining how it works, so this was very trial and error.
So I’m not sure on recommended sizes for the cache size in memory or on disk… any guidance would be very much appreciated!

iOS8
On iOS 8 though, this solution just does not work.
I haven’t been able to find any data on the Xamarin Forums (or anywhere else, including the apple forums) explaining how to do this, so perhaps it could be a limitation of the WKWebView? Or my google-fu is lacking?

Any information on how to set up the cache would be much appreciated!

NSUrlRequestCachePolicy
Also of interest, the caching policy on a Load request doesn’t seem to have much of an effect on either the UIWebView or the WKWebView.
For example, the code below does not ignore local cache and request a fresh copy from the server.
Is this a known issue, or am I perhaps not using it correctly?

webView.LoadRequest(new NSUrlRequest(new NSUrl(url), NSUrlRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData, 15));

Thanks in advance,
Basil


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>