I'm working on an iPad app project that is using Phonegap (cordova 2.0.0).
I know how to write a plugin so I can call a native method from the javascript, but what I really need now is to be able to call a Javascript method from my native code through a plugin. Something like:
- (void) callTestJsFunction
{
[super writeJavascript:@"testJsFunction();"];
}
that would call a testJsFunction()
located in one of my JS files in the www
folder. We're using Sencha Touch that handles some logic and I need to call a function from the app.js
.
I couldn't find any example of this kind on the web, so first I wonder if it is possible to do such a thing? and if so, how?
You have to create a plugin and put the native code there instead using it in the AppDelegate.m.
From the plugin class you can do this:
NSString* jsString = [NSString stringWithFormat:@"myJSFunction(\"%@\");", stringParameter];
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
Phonegap Cordova call javascript functions from Objective-C
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With