Nathan H Nathan H - 4 years ago 207
iOS Question

Receive message from JavaScript WebView in Objective-C

I have a WebView with a JavaScript function

, that makes some ajax calls.

In my AppDelegate, I've managed to to use WebView's stringByEvaluatingJavaScriptFromString to execute loadStuff.

Now my problem is I want to execute some Objective-C code once the JavaScript ajax stuff is done. How can my JavaScript notify back the native code?

Answer Source

If you have access to your AJAX success handler, you can just force webview to open some fake url from it and then handle this from delegate's shouldStartLoadWithRequest.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download