Created by Josh Bavari / @jbavari
My assumption is you've already chosen to have a hybrid application & youre wanting to know/understand how Cordova / Phonegap interacts with native plugins.
Lets take a look at The Device plugin's Plugin.xml file. During this talk, we will be going over the Device plugin
Device.prototype.getInfo = function(successCallback, errorCallback) {
argscheck.checkArgs('fF', 'Device.getInfo', arguments);
exec(successCallback, errorCallback, "Device", "getDeviceInfo", []);
};
//The plugin result will tell us whether its successful or not, in which either success calback
//or error callback will be called.
// This command will set up a result to pass back through the CordovaWebView
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties];
//Communicates to Webview the result
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("getDeviceInfo")) {
JSONObject r = new JSONObject();
r.put("uuid", Device.uuid);
r.put("version", this.getOSVersion());
r.put("platform", this.getPlatform());
r.put("cordova", Device.cordovaVersion);
r.put("model", this.getModel());
callbackContext.success(r);
}
else {
return false;
}
return true;
}
public void getDeviceInfo(string notused)
{
string res = String.Format("\"name\":\"{0}\",\"cordova\":\"{1}\",\"platform\":\"{2}\",\"uuid\":\"{3}\",\"version\":\"{4}\",\"model\":\"{5}\"",
this.name,
this.cordova,
this.platform,
this.uuid,
this.version,
this.model);
res = "{" + res + "}";
//Debug.WriteLine("Result::" + res);
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, res));
}
// This command will set up a result to pass back through the CordovaWebView
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties];
//Communicates to Webview the result
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
//create base plugin
plugman create --name Popups --plugin_id com.bavari.josh --plugin_version 1.0
//search for existing camera
plugman search camera
//create user to push to registry
plugman adduser
//publish plugin to official cordova registry
plugman publish Popups