728x90
WebView 를 사용해 보니 cache 때문에 반영된 최신 정보를 못가져오는 경우가 있다
아래 코드를 이용하면 항상 cache 를 clear 하고 가져오므로 이런 현상을 막을수 있다.
PCL
namespace Project.Controls
{
public class NoCachedWebView : WebView
{
}
}
{
public class NoCachedWebView : WebView
{
}
}
Android
[assembly: ExportRenderer(typeof(NoCachedWebView), typeof(NoCachedWebViewRenderer))]
namespace Project.Droid.Renderer
{
class NoCachedWebViewRenderer : WebViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
if (Control == null) return;
namespace Project.Droid.Renderer
{
class NoCachedWebViewRenderer : WebViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
if (Control == null) return;
Control.ClearCache(true);
Control.Settings.SetAppCacheEnabled(false);
Control.Settings.CacheMode = Android.Webkit.CacheModes.NoCache;
}
}
}
iOS
[assembly: ExportRenderer(typeof(NoCachedWebView), typeof(NoCachedWebViewRenderer))]
namespace Project.iOS.Renderer
{
class NoCachedWebViewRenderer : WebViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (Element == null) return;
namespace Project.iOS.Renderer
{
class NoCachedWebViewRenderer : WebViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (Element == null) return;
NSUrlCache.SharedCache.RemoveAllCachedResponses();
NSUrlCache.SharedCache.MemoryCapacity = 0;
NSUrlCache.SharedCache.DiskCapacity = 0;
}
}
}
728x90
'C# > Xamarin Maui' 카테고리의 다른 글
오류 - iOS) iTunesArtwork': Unknown image format, (0) | 2018.08.01 |
---|---|
authentication failure. Reason : {"authType" : "hsa2" } (0) | 2018.07.31 |
Xamarin.Forms 에서 장치별 unique ID 가져오기 (0) | 2018.07.17 |
Could not find any available provisioning profiles for iOS. WorkingWithMaps.iOS (0) | 2018.07.17 |
incompatible hax module version 3 requires minimum version 4 (0) | 2018.07.17 |