You can structure your plugin's JavaScript according to
your preference. However, you must use the cordova.exec() function to
communicate between the Cordova JavaScript and the native environment.
The
cordova.exec() function is defined in the
cordova.js file and has the following signature:
exec (successFunction, failFunction, service, action, [args]);
The parameters are:
- successFunction
- Success function callback. Assuming your exec() call completes successfully, this function is invoked (optionally
with any parameters you pass back to it).
- failFunction
- Error function callback. If the operation doesn't complete successfully, this function is invoked (optionally
with an error parameter).
- service
- The name of the service to call into on the native side. This is mapped to a native class.
- action
- The name of the action to call into. This parameter is used by the native
class receiving the cordova.exec() call, and essentially
maps to a class's method.
- args
- Arguments to pass into the native environment.
The cordova.exec() function is the key to your plugin—it
provides the link between the JavaScript and the native APIs. For more information about
cordova.exec(), see the Apache Cordova documentation.