Setting loading call backs to WKWebView

1.2k views Asked by At

How can I define callback functions for WKWebView in swift?

For UIWebView I used:

func webViewDidFinishLoad(_ : UIWebView)
{}

And connecting it as delegate

My WKWebView is defined:

@IBOutlet weak var containerView: UIView!
var wkwebView: WKWebView?
...
self.wkwebView = WKWebView()
self.view = self.wkwebView
1

There are 1 answers

0
liushuaikobe On BEST ANSWER

You could do this in navigationDelegate of WKWebView.

// your ViewController should adopt WKNavigationDelegate protocol
self.wkwebView.navigationDelegate = self

func webView(_ webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
    // similar to webViewDidFinishLoad:
}