ADDING CUSTOM CORDOVA PLUGIN

 

1. Create a plugin folder named cordova-plugin-getdirection under plugins folder of www (zigbank\platforms\ios\www\plugins) and create a www folder inside newly created folder and a .js file with the name mentioned in step-2 and it's contents as stated below.

For example,

cordova.define("cordova-plugin-getdirection", function(require, exports, module) {

var exec = cordova.require('cordova/exec');

exports.navigate = function(args, successCallback, errorCallback) {

cordova.exec(successCallback, errorCallback, "GetDirectionMapPlugin", "direction", [args]);

};

});

Here,

cordova-plugin-getdirection.getDirectionPlugin -> user defined id from cordova_plugins.js(zigbank\platforms\ios\ www\cordova_plugins.js)

GetDirectionMapPlugin: name of Obejective-C/Swift plugin class

direction: function to be called

navigate: this can be use in .js file to trigger this “direction” function

 

2. Make entry of plugin in cordova_plugins.js(zigbank\platforms\ios\www) as the following:

For example,

{

"id": "cordova-plugin-getdirection.getDirectionPlugin", : user defined id

“file”: “plugins/cordova-plugin-getdirection/www/mapgetdirection.js”, : path of plugin js file

"pluginId": "cordova-plugin-getdirection",

"clobbers": [

"window.getDirection": this can be used in any .js file to call plugin

]

}

 

3. Make entry of plugin class in config.xml(zigbank\platforms\ios\Zigbank) file of app as stated below:

For example,

<feature name="GetDirectionMapPlugin">

<param name="ios-package" value="GetDirectionMapPlugin" />

</feature>

The feature's name attribute should match what you specify as the JavaScript exec call's service parameter. The value attribute should match the name of the plugin's Objective-C/Swift class. The <param> element's name should always be ios-package. If you do not follow these guidelines, the plugin may compile, but Cordova may still not be able to access it.

 

4. Plugin invocation from any .js file:

For example,

window.getDirection.navigate({

originLatLng: origin,

destinationLatLng: location

})

window.getDirection : clobber defined in the cordova_plugin.js file

navigate: name of the function defined in plugin js file

 

Back