Back to All

Call an objective-c method from custom javascript

Hello,

Thanks to custom javascript added with Gonative website override, I would like to call a custom method "TestBridge" store in a file of my application. But I don't know in which file I have to define this method and I don't know how to call it.

Here is my javascript :

window.onload = function() {
  var specificPageUrl = "https://ide-plus.applicatif.net/v2/user/bdfa1cf0-98f3-4e98-b4b4-ea6a406337a9/1/0";

  if (window.location.href === specificPageUrl) {
    var buyButton = document.createElement("button");
    buyButton.innerHTML = "Je deviens IDEL++";
    buyButton.classList.add("primary-button-white", "w-button", "IDEL");

    var checkDivInterval = setInterval(function() {
      var IDELDiv = document.getElementById("IDEL-div");
      if (IDELDiv) {
        clearInterval(checkDivInterval);
        IDELDiv.style.display = "flex";
        IDELDiv.style.justifyContent = "center";
        IDELDiv.style.alignItems = "center";
        IDELDiv.appendChild(buyButton);
        
        buyButton.addEventListener("click", function() {
          window.webkit.messageHandlers.JSBridge.postMessage({
            functionName: "TestBridge",
            parameters: { }
          });
          alert("Test JavaScript");
        });
      }
    }, 100);

    setTimeout(function() {
      clearInterval(checkDivInterval);
    }, 5000);
  }
};

Could you please help me to write the "TestBridge" method that should display "Bridge Ok" in pop-up for example when the user click on the javascript button?

Thank you!