//iOS Plugin Development//Echo IOS Plugin Example//configured in CONFIG.<platform name= "ios" > <config-file target= "config" parent= "/*" > <feature name= "Echo" > <param name= "Ios-package" value= "Cdvecho"/> </feature> </config-file></platform>//Echo Header File#import <Cordova/CDC.h>@interface Cdvecho:cdvplugin//instance Method-(void) Echo: (Cdvinvokedurlcommand *) command; @end//Implementation Part#import "CDVEcho.h"#import<Cordova/CDC.h>@implementation Cdvecho-(void) Echo: (Cdvinvokedurlcommand *) command{Cdvpluginresult* Pluginresult =Nil; NSString* echo = [command.arguments objectatindex:0]; if(Echo! = nil && [echo length] > 0) {Pluginresult=[Cdvpluginresult Resultwithstatus:cdvcommandstatus_ok Messageasstring:echo]; } Else{Pluginresult=[Cdvpluginresult Resultwithstatus:cdvcommandstatus_error]; } [Self.commanddelegate Sendpluginresult:pluginresult callbackId:command.callbackId];} @end//Thread Handling- (void) Mypluginmethod: (cdvinvokedurlcommand*) command{//Check command.arguments here.[Self.commanddelegate runinbackground:^{nsstring* Payload =Nil; //Some blocking Logic ...cdvpluginresult* Pluginresult =[Cdvpluginresult Resultwithstatus:cdvcommandstatus_ok messageasstring:payload]; //The Sendpluginresult method is Thread-safe.[Self.commanddelegate Sendpluginresult:pluginresult callbackId:command.callbackId]; }];}//^{}: Used to wait for the last block in the queue to be executed, one of the common operations//^ This thing, the description of a block function, () This thing is a block inside the required parameter {} execution body//It is important to note that Weakself is not directly using self to prevent circular referencing[Self.commanddelegate runinbackground:^{}]; JavaScript:1. Successfunction: A successful callback function2. Failfunction: An error callback function3. Service: A local class name4. Action: Local class method Name5. Args: Parameters of an array are passed to the local environment, exec (<successfunction>, <failfunction>, <service>, <action>, [<args>]); Sample://definitionCordova.define ("com. JajaCy.cordova.echo ",function(Require, exports, module) {varexec = require (' cordova/exec '); varPlatform = require (' Cordova/platform ')); /** * Provides access to Echo on the device. * Provide notifications on your device. */Module.exports= { /** Demo * @param {String} message * @param {Function} completecallback*/Echo:function(message,callback) {exec (callback,function(Err) {Callback (' Nothing to echo. '); }, "Echo", "echo", [message]); } };});//cordova_plugins.js plug-in configurationCordova.define (' Cordova/plugin_list ',function(Require, exports, module) {module.exports= [{ "File": "Plugins/com." Jajacy.cordova.echo/www/echo.js ", "id": "com." JajaCy.cordova.echo.echo ", "Merges": [ "Window"//Call Method Object ] }]; Module.exports.metadata=//TOP of METADATA { "com. JajaCy.cordova.echo ":" 0.0.1 ", } //BOTTOM of METADATA});//calledWindow.echo (' Hello echo! ',function(data) {alert (data);});
cordova+ iOS Plugin Development