title: WKScriptMessageHandler does not work ios swift xcode
body: <p>Please tell me, is there such a code.
  When the webview loads, the page sends postMessage.
  For some reason, print does not work.</p>
  <p>ViewController.swift:</p>
  <pre><code>import UIKit
  import WebKit
  class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler {
      
      var webView: WKWebView!
      
      override func loadView() {
          webView = WKWebView()
          webView.navigationDelegate = self
          view = webView
      }
      
      override func viewDidLoad() {
          super.viewDidLoad()
          let url = URL(string: &quot;https://web.site/&quot;)!
          webView.load(URLRequest(url: url))
          let config = WKWebViewConfiguration()
          let userContentController = WKUserContentController()
          userContentController.add(self, name: &quot;test&quot;)
          config.userContentController = userContentController
      }
      
      func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
          if message.name == &quot;test&quot;, let messageBody = message.body as? String {
              print(messageBody)
          }
      }
  }
  
  </code></pre>
  <p>index.html:</p>
  <pre><code>&lt;script&gt;
      function printHelloWorld() {
          window.webkit.messageHandlers.test.postMessage(&quot;Hello, world!&quot;);
      }
      window.onload = printHelloWorld;
  &lt;/script&gt;
  </code></pre>
  <p>Please tell me what could be the problem?</p>