【发布时间】:2013-08-05 13:31:07
【问题描述】:
我正在为 iOS 应用创建 Phonegap/Cordova(版本 2.9.0)自定义插件。我的步骤如下:
-
我创建了一个 HelloPlugin.js 文件并将其复制到 www/js/ 文件夹下,其中包含代码:
var HelloPlugin = { callNativeFunction: function (success, fail, resultType) { alert('a'); return Cordova.exec( success, fail, "HelloPlugin", "nativeFunction", ['1']); } }; -
我在plugins文件夹下创建了HelloPlugin.h和HelloPlugin.m文件,代码:
// .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!"); } @end -
我在 config.xml 文件中添加了以下代码:
<feature name="HelloPlugin"> <param name="ios-package" value="CDVPlugin"/> </feature> -
最后我用以下方式修改了 index.html:
- 添加了脚本参考。 ()
-
已添加 JS 代码:
function callNativePlugin(returnSuccess) { HelloPlugin.callNativeFunction( nativePluginResultHandler, nativePluginErrorHandler, returnSuccess ); } function nativePluginResultHandler (result) { alert("SUCCESS: \r\n"+result ); } function nativePluginErrorHandler (error) { alert("ERROR: \r\n"+error ); } -
添加了两个按钮并调用了函数:
"callNativePlugin('成功');" "callNativePlugin('error');"
我希望这是激活插件所需要做的唯一事情。
问题:在运行应用程序时,我在控制台上收到 FAILED pluginJSON 错误。
输出:
-[CDVCommandQueue executePending] [第 116 行] FAILED pluginJSON = [ "HelloPlugin2650437", "你好插件", “本机功能”, [ "1", "1", “1” ] ]
我犯了什么错误,请告诉我。我真的很感谢你的努力。请在这里帮助我。
【问题讨论】: