Hi,
How can i do webpage show offline mode in Xamarin.forms.webpage
I guess, I have to do render webpage for each platform.But how?
These are my sample code:
` public class WebAppPage : BasePage
{
private WebAppView MyWebAppView;
public WebAppPage(string targetUrl)
{
NavigationPage.SetHasNavigationBar(this, false);
var stack = new StackLayout
{
Orientation = StackOrientation.Vertical,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
};
if (MyWebAppView == null)
{
MyWebAppView = new WebAppView
{
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
Source =targetUrl
};
}
stack.Children.Add(MyWebAppView);
Content = stack;
}
`
and my web page renderer class for ios is:
`[assembly:ExportRenderer(typeof(WebAppView),typeof(WebAppViewRenderer))]
namespace Sample.Wrapper.iOS
{
public class WebAppViewRenderer:WebViewRenderer
{
public WebAppViewRenderer()
{
Debug.WriteLine("WebAppViewRenderer()");
}
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.OldElement==null)
{
var cache = new NSUrlCache { DiskCapacity = 512 * 1024 };
//this.AllowsInlineMediaPlayback = true;
//NSData myPage = NSData.FromString (this.);
//this.LoadData (myPage, "text/html", "UTF-8", new NSUrl (contentDirectoryPath, true))
// this.LoadRequest(new NSUrlRequest(new NSUrl(url.Url)));
this.ScalesPageToFit = true;
this.ScrollView.ScrollEnabled = false;
this.Delegate = new MyCustomWebViewDelegate();
this.ShouldStartLoad += HandleShouldStartLoad;
}
}
private bool HandleShouldStartLoad(UIWebView webview, NSUrlRequest request, UIWebViewNavigationType navigationtype)
{
var scheme = "hybrid";
if (request.Url.Scheme!=scheme.Replace(":",""))
{
return true;
}
return false;
}
}`
Thanks..