user3383301
user3383301

Reputation: 1911

Cordova IOS Plugin not found when i run the project

I have created an cordova project cordova create sampleApp com.sample.app sampleApp then i did cordova platform add ios and then cordova plugin add cordova-plugin-device

Files :

platforms/ios/ios.json

In the ios.json i have added an custom plugin called sayHelloPlugin inside the below json

{
    "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

In config.xml also i have added

<feature name="sayHelloPlugin">
        <param name="ios-package" value="sayHelloPlugin" />
 </feature>

www/js/index.js I added the call to native objective c functions as

cordova.exec(sayHelloSuccess, sayHelloFailure, "SayHelloPlugin", "sayHello", [name]);

function test(){        
     alert("Received Event");
}

function sayHelloSuccess(data){
    alert("Success");
}

function sayHelloFailure(data){
    alert("Error");
}

And my objective class looks like

#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

When i do an cordova build ios the build is successfull . When i emulate and run i get an error message

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"]]

How to fix this ??

Upvotes: 0

Views: 1283

Answers (2)

y-dolem
y-dolem

Reputation: 62

Creating a Custom plugin you may need to use Plugman.

1) Install Plugman

$npm install -g plugman

2) Start on creating your Custom plugin using Plugman in CLI, command as follows:

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

3) Add the platform for your custom plugin

plugman platform add --platform_name ios

4) Create and add a package.json

Note: If it hits 'EACCESS: permission denied, open.." Please add 'sudo' in front of the command

plugman createpackagejson pluginName

Refer doc link: https://cordova.apache.org/docs/en/latest/guide/hybrid/plugins/index.html

Upvotes: -2

Raymond Camden
Raymond Camden

Reputation: 10857

The error clearly says the sayHelloPlugin wasn't found. You demonstrated how you added the device plugin, but not this particular plugin.

Upvotes: 0

Related Questions