我已经阅读了 Cordova 的教程,但我不确定他们是否给了我足够的信息。
编辑显示更新的代码:
让我向您展示我的代码:
从 config.xml:
<plugin name="someMethod" value="MyPluginClass" />
现在对于 Plugin.h:
#import <Cordova/CDV.h>
@interface MyPluginClass : CDVPlugin
- (void)someMethod:(CDVInvokedUrlCommand*)command;
@end
现在对于 Plugin.m:
#import "Plugin.h"
@implementation MyPluginClass
- (void)someMethod:(CDVInvokedUrlCommand *)command
{
NSLog(@"YOU ARE READING THIS NATIVELY FROM A PLUGIN");
}
@end
显示的第一个 html 页面称为“index.html”
我只想要一个空白的 html 页面,它只运行一个调用 cordova.exec() 函数的脚本。我这样做的尝试失败了。我不知道是我的脚本做错了什么还是我在其他地方做错了什么,但这是我的 index.html:
<!DOCTYPE html>
<html>
<head>
<title>Cordova Device Ready Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.3.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Call onDeviceReady when Cordova is loaded.
//
// At this point, the document has loaded but cordova-2.3.0.js has not.
// When Cordova is loaded and talking with the native device,
// it will call the event `deviceready`.
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// Cordova is loaded and it is now safe to make calls Cordova methods
//
function onDeviceReady() {
// Now safe to use the Cordova API
document.addEventListener("deviceready", function() {
cordova.exec(null,null,"MyPluginClass","someMethod",[]);
}, false);
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>
我收到以下错误日志:
2013-01-17 11:36:31.782 CCT [1293:907] 错误:找不到插件“MyPluginClass”,或者不是 CDVP 插件。检查 config.xml 中的插件映射。
2013-01-17 11:36:31.787 CCT[1293:907] -[CDVCommandQueue executePending] [第 103 行] 失败 pluginJSON = ["INVALID","MyPluginClass","someMethod",[]]