I tried to implement a CustomWebViewRenderer for iOS so I can append header to the request later on. I can see a border surrounded the web view but can't see the background which have the same color as the border. Only see a white blank space inside the border.
public class CustomWebViewRenderer : ViewRenderer<CustomWebView, UIWebView>
{
protected override void OnElementChanged(ElementChangedEventArgs<CustomWebView> e)
{
base.OnElementChanged(e);
var control = new UIWebView();
control.Layer.BorderColor = new CoreGraphics.CGColor(1.0f, 1.0f, 0.0f);
control.Layer.BorderWidth = 10;
control.Layer.BackgroundColor = new CoreGraphics.CGColor(1.0f, 1.0f, 0.0f);
control.Delegate = new WebViewDelegate(control, Element.Token);
SetNativeControl(control);
if (!String.IsNullOrEmpty(Element.Token) && !String.IsNullOrEmpty(Element.Url))
{
Control.LoadRequest(new NSUrlRequest(new NSUrl(Element.Url)));
}
}
protected void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
var element = ((CustomWebView)Element);
if (e.PropertyName.Equals(nameof(element.Token)))
{
((WebViewDelegate)Control.Delegate).Token = element.Token;
Control.LoadRequest(new NSUrlRequest(new NSUrl(Element.Url)));
}
}
class WebViewDelegate : UIWebViewDelegate
{
public string Token { get; set; }
private UIWebView _view;
public WebViewDelegate(UIWebView view, string token)
{
_view = view;
Token = token;
}
public override bool ShouldStartLoad(UIWebView webView,
NSUrlRequest request,
UIWebViewNavigationType navigationType)
{
//request.Headers.SetValueForKey((NSString)"Authorization", (NSString)("Bearer " + Token));
return true;
}
Do I need any edit anything in the .plist file like Android for internet permission.