Biny

Xamarin.Forms Webkit custom User Agent String

Biny 2021-10-26 10:22:31    726 次浏览

public class CustomWebViewRenderer : WebViewRenderer

{

private readonly Context _context;

public CustomWebViewRenderer(Context context) : base(context)

{

_context = context;

}

protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)

{

base.OnElementChanged(e);

if (e.NewElement != null)

{

Control.SetWebViewClient(GetWebViewClient());

Control.Settings.UserAgentString = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) Kzwr/1.0 (KHTML, like Gecko) BC3 iOS/3.12.4 (build 523; iPhone XR; iOS 13.3.1)";

}

}

}

内容加载中