cordova+ iOS Plugin Development

Source: Internet
Author: User

//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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.