1 year ago

#385412

test-img

Anoop Vaidya

Delegate method `WKWebView CreateWebView` method is not getting called

I am using Xamarin (C#) code for a macOS app. I have created the WKWebView and have outlet, added Navigation and UI delegates and trying to open an URL.

The Navigation delegates methods are getting called, but not sure what am I missing that UI Delegates method is not getting called.

Any help / guidance what to look for, or what mistake I am doing here, please.

Here's the code and image of same:

public override void ViewDidLoad()
{
        base.ViewDidLoad();

        var url = new NSUrl("https://google.com");
        var request = new NSMutableUrlRequest(url);


        _webView.UIDelegate = new WebViewDelegate();
        _webView.NavigationDelegate = new WebViewNavigationDelegate();

        _webView.LoadRequest(request);

    }
}

internal class WebViewDelegate : WKUIDelegate
{
    public override WKWebView CreateWebView(WKWebView webView, WKWebViewConfiguration configuration, WKNavigationAction navigationAction, WKWindowFeatures windowFeatures)
    {
        Console.WriteLine("this doesn't reach");

        return null;
    }
}

internal class WebViewNavigationDelegate : WKNavigationDelegate
{
    public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
    {
        Console.WriteLine("this prints");
    }
}

enter image description here

xamarin

cocoa

wkwebview

0 Answers

Your Answer

Accepted video resources