title: Swift: WKWebView add javascript interface like Android
body: <p>I have a page that I want to display in a webview with dynamic content.</p>
  
  <p>On Android I can do it simple by interface, here is the interface:</p>
  
  <pre><code>class WebAppInterface (val context: Context, val userId: Long, val  type: String) {
      @JavascriptInterface
      fun getId(): Long {
          return userId
      }
  
      @JavascriptInterface
      fun getBaseUrl(): String{
         return Configuration.getInstance().userConfig.getStoredBaseUrl();
      }
  
      @JavascriptInterface
      fun getGetStatType(): String{
         return type;
      }
  }
  </code></pre>
  
  <p><code>webview.addJavascriptInterface(WebAppInterface(this.applicationContext, id, statisticsType!! ), "android")</code></p>
  
  <p>How can I do the same thing on iOS, after my search I got this:</p>
  
  <pre><code>let contentController = WKUserContentController()
          contentController.add(self, name: "android") // -&gt; Set a listener
  
          let config = WKWebViewConfiguration()
          config.userContentController = contentController
  
          let scriptString = "????? What write ir?"
          let script = WKUserScript(source: scriptString, injectionTime: WKUserScriptInjectionTime.atDocumentEnd, forMainFrameOnly: true)
          config.userContentController.addUserScript(script)
  
          webView = WKWebView(frame: .zero, configuration: config)
  </code></pre>
  
  <p>And the delegate method:</p>
  
  <pre><code> func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
      print(message)
  }
  </code></pre>
  
  <p>In the delegate method it does not print when it arrives on the keyword android? Why? Did I misunderstand the operation?
  Here is some of my js code that works well with the androidInterface</p>
  
  <pre><code>function getSteps() {
      const url = android.getBaseUrl() + 'patient/' + android.getId() + '/statistics/steps?from=' + from + '&amp;to=' + to;
      Http.open("GET", url);
      Http.setRequestHeader('Authorization', 'Bearer ' + android.getToken())
      Http.send();
  }
  </code></pre>
  
  <p>How can I inject the values into the "android" js, as I did on android.</p>