0

I'm trying to display some content in Xamarin IOS app using WKWebView. The code is pretty straightforward:

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);
    }
}

This works fine in simulator in iOS 13, but in iOS 11 I'm getting blank screen despite the fact that in the NavigationDelegate I can check that content from web was loaded without errors. What's the problem with WKWebView in iOS 11?

Zukimo
  • 1
  • 1
  • 2

1 Answers1

0

I do not use damaging, but in native swift code, is wrong to instantiate a delegate: you should delegate any existing object, usually a controller. In that controller You will be called.

see also here: How to check if WkWebView finish loading in Objective-C?

ingconti
  • 9,213
  • 2
  • 51
  • 39
  • It works fine and DidFinishNavigation is called after simpleWebView finishes loading content. – Zukimo Jul 31 '20 at 18:33
  • It seems that i've found the solution. The problem might be related with the content of the page I tried to load. – Zukimo Jul 31 '20 at 19:25