I'm working on a Phonegap/Cordova(version 2.9.0) custom plugin creation for iOS app. My steps are as follows :
I created a HelloPlugin.js file and copy it under www/js/ folder, its having code :
var HelloPlugin = { callNativeFunction: function (success, fail, resultType) { alert('a'); return Cordova.exec( success, fail, "HelloPlugin", "nativeFunction", ['1']); } };I created HelloPlugin.h and HelloPlugin.m files under plugins folder, code :
// .h #import <Cordova/CDVPlugin.h> @interface HelloPlugin : CDVPlugin - (void)nativeFunction:(CDVInvokedUrlCommand*)command; @end // .m #import "HelloPlugin.h" @implementation HelloPlugin - (void)nativeFunction:(CDVInvokedUrlCommand*)command { NSLog(@"Hello, this is a native function called from PhoneGap/Cordova!"); } @endI added following code to config.xml file :
<feature name="HelloPlugin"> <param name="ios-package" value="CDVPlugin"/> </feature>At last I modified index.html in following way :
- Script reference added. ()
JS code added :
function callNativePlugin(returnSuccess) { HelloPlugin.callNativeFunction( nativePluginResultHandler, nativePluginErrorHandler, returnSuccess ); } function nativePluginResultHandler (result) { alert("SUCCESS: \r\n"+result ); } function nativePluginErrorHandler (error) { alert("ERROR: \r\n"+error ); }Two buttons added and function called:
"callNativePlugin('success');" "callNativePlugin('error');"
I hope this is the only required things I need to do for activating plugin.
Issue : While running the app, I am getting FAILED pluginJSON error on console.
Output :
-[CDVCommandQueue executePending] [Line 116] FAILED pluginJSON = [ "HelloPlugin2650437", "HelloPlugin", "nativeFunction", [ "1", "1", "1" ] ]
What mistake I have done, please let me know. I really Appreciate your efforts. Please help me here.