【发布时间】:2020-07-31 15:53:34
【问题描述】:
我正在尝试使用 WKWebView 在 Xamarin IOS 应用程序中显示一些内容。代码非常简单:
public override void ViewDidLoad()
{
base.ViewDidLoad();
var simpleWebView = new WKWebView(View.Frame, new WKWebViewConfiguration());
Add(simpleWebView);
simpleWebView.NavigationDelegate = new WKWebViewDelegate();
simpleWebView.LoadRequest(new NSUrlRequest(new NSUrl("https://myurl_here")));
}
public class WKWebViewDelegate : WKNavigationDelegate
{
public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
{
WKJavascriptEvaluationResult handler = (NSObject result, NSError err) => {
if (err != null)
{
//Do smth
}
if (result != null)
{
//Do smth
}
};
webView.EvaluateJavaScript("(function() { return ('<html>' + document.getElementsByTagName('html')[0].innerHTML + '</html>'); })(); ", handler);
}
}
这在 iOS 13 的模拟器中运行良好,但在 iOS 11 中,尽管在 NavigationDelegate 中我可以检查来自 web 的内容是否已加载且没有错误,但我却得到了空白屏幕。 iOS 11 中的 WKWebView 有什么问题?
【问题讨论】: