I want to pass one url in my webview. But as IOS appstore gives error so I want to implement WKWebview but I want to know how can implement it? Please help me out its urgent.
You can use WKWebView via Custom Renderer. Create a custom WebView in your PCL and define a bindable property pointing what url should be loaded on iOS.
public class local : CustomWebView: WebView
{
public static readonly BindableProperty UrlProperty = BindableProperty.Create(
propertyName: "Url",
returnType: typeof(string),
declaringType: typeof(CustomWebView),
defaultValue: default(string));
public string Url
{
get { return (string)GetValue(UrlProperty); }
set { SetValue(UrlProperty, value); }
}
}
CustomRenderer.cs
[assembly: ExportRenderer(typeof(CustomWebView), typeof(CustomWebViewRenderer))]
namespace WKWebViewDemo.iOS
{
public class CustomWebViewRenderer : ViewRenderer<CustomWebView, WKWebView>
{
WKWebView wkWebView;
protected override void OnElementChanged(ElementChangedEventArgs<CustomWebView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
var config = new WKWebViewConfiguration();
wkWebView = new WKWebView(Frame, config);
SetNativeControl(wkWebView);
}
if (e.NewElement != null)
{
Control.LoadRequest(new NSUrlRequest(new NSUrl(Element.Url)));
}
}
}
}
@Gandhi_123 Any updates? If you have solved the problem, please mark the helpful solution as answer which will help others who face the similar problem. If you are facing some issues while implementing, try to post the particular error with the corresponding codes here.
There is no reason to write your own custom renderer, Xamarin.Forms has already provided a WebView renderer that uses WkWebView instead of UIWebView. In Xamarin.Forms 4.4.0, the WkWebViewRenderer will be made the default.
Until then, simply add this line somewhere in your iOS project. [assembly: ExportRenderer(typeof(Xamarin.Forms.WebView), typeof(Xamarin.Forms.Platform.iOS.WkWebViewRenderer))]
[assembly: ExportRenderer(typeof(PaymentWebview), typeof(PaymentWebViewRenderer))]
namespace MMFInvestorApp.iOS.Utils
{
public class PaymentWebViewRenderer : WkWebViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (NativeView != null)
{
var request = new NSMutableUrlRequest(new NSUrl(new NSString(paymentwebview.url))); //Your Url
request.HttpMethod = "POST";
request.Body = NSData.FromString(paymentwebview.data); //Data for POST
request["Content-Length"] = req.Body.Length.ToString();
request["Content-Type"] = "application/x-www-form-urlencoded charset=utf-8";
LoadRequest(request);
}
}
}
}
For UIWebview (Deprecated from April 2020
[assembly: ExportRenderer(typeof(PaymentWebview), typeof(PaymentWebViewRenderer))]
namespace MMFInvestorApp.iOS.Utils
{
public class PaymentWebViewRenderer : WebViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (NativeView != null)
{
var paymentwebview = Element as PaymentWebview;
var request = new NSMutableUrlRequest(new NSUrl(new NSString(paymentwebview.url)));//Your Url
request.Body = paymentwebview.data; //Data for POST
request.HttpMethod = "POST";
LoadRequest(request);
}
}
}
I am facing the same issue so please help me If you have solved the problem, please mark the helpful solution as an answer which will help others who face a similar problem.
Answers
Its not an error, its a warning. And there are many existing threads on the subject.
You can use WKWebView via Custom Renderer. Create a custom WebView in your PCL and define a bindable property pointing what url should be loaded on iOS.
CustomRenderer.cs
Then se the custom view in page.xaml
Refer to:
https://stackoverflow.com/questions/42504016/how-can-i-use-wkwebview-instead-of-uiwebview-in-xamarin-forms-webviewios/42524772
@Gandhi_123 Any updates? If you have solved the problem, please mark the helpful solution as answer which will help others who face the similar problem. If you are facing some issues while implementing, try to post the particular error with the corresponding codes here.
There is no reason to write your own custom renderer, Xamarin.Forms has already provided a WebView renderer that uses WkWebView instead of UIWebView. In Xamarin.Forms 4.4.0, the WkWebViewRenderer will be made the default.
Until then, simply add this line somewhere in your iOS project.
[assembly: ExportRenderer(typeof(Xamarin.Forms.WebView), typeof(Xamarin.Forms.Platform.iOS.WkWebViewRenderer))]
IS THERE ANY WAY TO SET ENABLE ZOOM FUNCTION?
In UIWebView, there's ScalePageToFit to enable zooming.
Anyone know?
For WKWebView , Navigated and navigating methods
step 1:
public class ExtendedWebView: WebView
{
public ExtendedWebView()
{
}
.......................
step -2
namespace *** .iOS.Renderer
{
public class ExtendedWebViewRenderer : ViewRenderer<ExtendedWebView, WKWebView>
{
public ExtendedWebViewRenderer()
{
}
WKWebView webView;
}
step 3:
templates:ExtendedWebView x:Name="extendedWebView" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" LoadingStart="ExtendedWebView_LoadingStart" LoadingFinished="ExtendedWebView_LoadingFinished"
POST Request Over Webview
For WkWebview
[assembly: ExportRenderer(typeof(PaymentWebview), typeof(PaymentWebViewRenderer))]
namespace MMFInvestorApp.iOS.Utils
{
public class PaymentWebViewRenderer : WkWebViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
}
For UIWebview (Deprecated from April 2020
[assembly: ExportRenderer(typeof(PaymentWebview), typeof(PaymentWebViewRenderer))]
namespace MMFInvestorApp.iOS.Utils
{
public class PaymentWebViewRenderer : WebViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
}
Hello Guys,
I am facing the same issue so please help me If you have solved the problem, please mark the helpful solution as an answer which will help others who face a similar problem.
Thanks
Hello All,
It is working for me. But when i use this custom renderer for iOS, Accessibility is stopped working on loaded page in web view. Please help.