Reputation: 3963
I'm using the webView:shouldStartLoadWithRequest:navigationType
method to call my Objective-C code from JavaScript which works OK. The problem is, this method only gets called when a Web view reloads. I want to be able to send messages "whenever I want". Is that possible?
Specifically I want to use document.location = "myapp:" + "customerAdded:" + "YES";
as often as I please. My code only gets executed when I draw the map using Google API V3.
Is it possible to reload an "invisible" frame in order to call the delegate method?
Upvotes: 0
Views: 157
Reputation: 37581
try this, works fine for me
function invokeObjectiveC() {
var iframe = document.createElement("IFRAME");
iframe.setAttribute(your stuff here);
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
}
Upvotes: 1
Reputation: 50707
webView:shouldStartLoadWithRequest:navigationType:
should only be called when the web view reloads, that's the purpose of this delegate. You can use NSNotificationCenter
to call a method that reloads your webview.
Upvotes: 0