Good day!

There is such a question: We have a UIViewController on which the UIWebView is located, in the process of working up in the UIWebView, the site is loaded in which there is a link

<a href="" onclick="mobile_app.performClick()">Проверить</a> 

So, when you click on this link in a mobile browser, you need to run some code in the classes of the application. In the Android version this is done like this -

 w.addJavascriptInterface(new Object() { @SuppressWarnings("unused") public void performClick() { startScanActivity(); } }, 

where w = (WebView) findViewById (R.id.mainWebView);

THOSE. we intercept the JS onClick event and if it is equal to performClick, then we perform the functions of the application.

Task: repeat the same on iOS

I hope for your help! Thank you in advance!

    1 answer 1

    Perhaps there are other ways, but I used only one - send a request to somewhere from js and intercept it in UIWebViewDelegate в - (BOOL)webView:(UIWebView*) webView shouldStartLoadWithRequest:(NSURLRequest *) request navigationType:(UIWebViewNavigationType) navigationType a couple of related links:

    • There was a similar solution - imaladec.com/story/objective_c_and_javascript , but it didn’t really fit me. The fact is that IOS requires writing a relocation function function ObjCAlert () {document.location = "jsexample: alert: iMaladec_alert_from_JS"; }; and this function - reload the page and then only it is enough for IOS, but Android - this reload is completely unnecessary. - BlackWidow
    • then I don’t know if only to execute different code depending on the host axis - aknew
    • Thank! Actually, that's what they did, from the host axis and that's it. :) - BlackWidow