尽可能多地拼凑代码 http://docs.phonegap.com/en/edge/guide_hybrid_plugins_index.md.html#Plugin%20Development%20Guide_sample_javascript和 http://docs.phonegap.com/en/edge/guide_platforms_ios_plugin.md.html#iOS%20Plugins我试图制作一个使用“Echo”插件的演示。
它不起作用。
在 Safari 的 Web Inspector 中,我在 iPhone 模拟器上运行时得到以下信息:
[Log] Received Event: deviceready (index.js, line 47)
[Error] TypeError: '[object Object]' is not a function (evaluating 'window.echo("echome", function(echoValue) {
alert(echoValue == "echome"); // should alert true.
})')
receivedEvent (index.js, line 49)
onDeviceReady (index.js, line 36)
fire (cordova.js, line 750)
(anonymous function) (cordova.js, line 223)
我对这个插件实现的最佳理解是:https://github.com/thegreatmichael/phonegap-echo-plugin-example我对如何使用它的最佳理解(我尽可能少地修改了基本的、生成的应用程序)在这里:https://github.com/thegreatmichael/phonegap-app-uses-echo
我应该怎么做才能获得 echo 插件的工作示例?
最佳答案
我认为您的问题是因为在 plugin.xml 中您使用了 clobbers
但在你的 js 中你不使用 module.exports
导出您的插件对象。
您必须使用 <runs/>
而不是 <clobbers target="echo" />
或修改您的 js 以使用 module.exports(查看示例的核心 cordova 插件)。
关于ios - 如何为 Cordova 实现自定义插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21391298/