繁体   English   中英

运行项目时找不到Cordova IOS插件

[英]Cordova IOS Plugin not found when i run the project

我创建了一个cordova项目cordova创建sampleApp com.sample.app sampleApp,然后我做了cordova平台添加了ios,然后cordova插件添加了cordova-plugin-device

文件:

platform / 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
                        }
                    ]
                }
            }
        }
    },

}

platform / 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

当我做一个cordova build 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"]]

如何解决这个问题?

该错误明确表明未找到sayHelloPlugin。 您演示了如何添加设备插件,但未添加特定插件。

创建自定义插件,您可能需要使用Plugman。

1)安装Plugman

$npm install -g plugman

2)开始使用CLI中的Plugman创建您的自定义插件,命令如下:

plugman create --name pluginName --plugin_id "com.pluginName" --plugin_version 1.0.0 --project "PLUGIN_DIR/com.pluginName"

3)为您的自定义插件添加平台

plugman platform add --platform_name ios

4)创建并添加一个package.json

注意:如果点击“ EACCESS:权限被拒绝,请打开。”。请在命令前面添加“ sudo”

plugman createpackagejson pluginName

请参阅文档链接: https : //cordova.apache.org/docs/en/latest/guide/hybrid/plugins/index.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM