【发布时间】:2016-04-24 19:23:52
【问题描述】:
我创建了一个 cordova 项目 cordova create sampleApp com.sample.app sampleApp 然后我做了cordova平台添加ios,然后cordova插件添加cordova-plugin-device
文件:
平台/ios/ios.json
在 ios.json 中,我在下面的 json 中添加了一个名为 sayHelloPlugin 的自定义插件
{
"prepare_queue": {
"installed": [],
"uninstalled": []
},
"config_munge": {
"files": {
"config.xml": {
"parents": {
"/*": [
{
"xml": "<feature name=\"Device\"><param name=\"ios-package\" value=\"CDVDevice\" /></feature>",
"count": 1
},
{
"xml": "<feature name=\"sayHelloPlugin\"><param name=\"ios-package\" value=\"sayHelloPlugin\" /></feature>",
"count": 1
}
]
}
}
}
},
}
platforms/ios/sampleApp/config.xml
在 config.xml 中我也添加了
<feature name="sayHelloPlugin">
<param name="ios-package" value="sayHelloPlugin" />
</feature>
www/js/index.js 我添加了对本机目标 c 函数的调用作为
cordova.exec(sayHelloSuccess, sayHelloFailure, "SayHelloPlugin", "sayHello", [name]);
function test(){
alert("Received Event");
}
function sayHelloSuccess(data){
alert("Success");
}
function sayHelloFailure(data){
alert("Error");
}
我的目标类看起来像
#import "SayHelloPlugin.h"
@implementation SayHelloPlugin
- (void)sayHello:(CDVInvokedUrlCommand*)command{
NSString *responseString =
[NSString stringWithFormat:@"Hello %@", [command.arguments objectAtIndex:0]];
CDVPluginResult *pluginResult =
[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:responseString];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@end
当我进行科尔多瓦构建 ios 时,构建成功。 当我模拟并运行时,我收到一条错误消息
2016-01-19 05:39:44.017 sampleApp[21225:1854134] CDVPlugin class sayHelloPlugin (pluginName: SayHelloPlugin) does not exist.
2016-01-19 05:39:44.018 sampleApp[21225:1854134] ERROR: Plugin 'SayHelloPlugin' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2016-01-19 05:39:44.018 sampleApp[21225:1854134] -[CDVCommandQueue executePending] [Line 159] FAILED pluginJSON = ["SayHelloPlugin535510559","SayHelloPlugin","sayHello",["Hello"]]
如何解决这个问题?
【问题讨论】:
标签: ios iphone xcode cordova cordova-plugins