简体   繁体   中英

Calling Objective C function from UIWebView using Ajax

I found online a tutorial where it says that ObjectiveC code can be called from a WebView using the following Javascript code

var iframe = document.createElement("IFRAME");
iframe.setAttribute("src", "js-frame:myObjectiveCFunction");
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;

Then from ObjectiveC I must implement UIWebViewDelegate to receive the shouldStartLoadWithRequest. I tried this code and it worked; however, I was wondering if the same functionality could be implemented using an AJAX call instead of using an IFrame.

It can be done if you change window.location with JS. it will invoke the delegate function you're using.

You may also use links on your page to execute an obj-c function using the same delegate method.

If you're planning to do a special call using AJAX, please explain it more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM