Jordan Benge
1 min readFeb 12, 2019

--

I’m glad you found it helpful and liked it!

As for passing arguments to a function, it’s pretty straight forward, if you followed the article. I’ve bolded the parts that have to be added, for clarity.

In YourPluginName.js file

YourPluginName.someFunction = function(options, onSuccess, onError) {
...
exec(onSuccess, onError, PLUGIN_NAME, "someFunction", [options.first, options.second, options.third...]);
}

Where options.first, options.second, options.third… are the parameters you want to pass to the Plugin.

In your PluginName.swift file you can access the passed parameters via:

@objc(YourPluginName) class YourPluginName : CDVPlugin {
@objc(yourFunctionName:) // Declare your function name.
func yourFunctionName(command: CDVInvokedUrlCommand) { // write the function code.
// let firstParam = command.arguments![0];
// let secondParam = command.arguments![1];
...
}

Lastly, in your Ionic Native implementation, all you have to do is pass the arguments into the function call.

@Cordova({
successIndex: 0,
errorIndex: 1
})
yourFunctionName(options: any): Promise<any> {
return;
}
}

Then you can properly call the function with the arguments

public someFunctionName(options: any){
this.yourPluginName.yourPluginFunction(options).then(() => {
console.log("The yourPluginFunction ran without errors!");
}).catch(err => {
console.log("yourPluginFunction encountered the following error: ",err);
})
}

And with that, you should be good to go!

--

--

Jordan Benge
Jordan Benge

Written by Jordan Benge

My name is Jordan Benge, I’m a freelance developer, who sometimes likes to write helpful articles on Medium for people who want to do things but don’t know how.

Responses (1)