Search code examples
javascriptiosobjective-cios7

Receive message from JavaScript WebView in Objective-C


I have a WebView with a JavaScript function loadStuff, 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?


Solution

  • 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.