Giter Club home page Giter Club logo

sampleiosplugin's Introduction

Install Plugman :

npm install -g plugman

Create Plugin project :


plugman create --name <pluginName> --plugin_id <pluginID> --plugin_version <version> --path <directory-where-plugin-should-be-created>

Folder Structure :

Plugin Project Directory
	
|_________ plugin.xml
	|_________	www
	|	|_________ <plugin-name>.js
	|_________	src
	|	|_________ ios
	|	|	|_________<plugin-name>.h
	|	|	|_________<plugin-name>.m

Plugin.xml :

<?xml version='1.0' encoding='utf-8'?>
<plugin id=“<plugin-id>”
        version="0.0.1"
        xmlns="http://apache.org/cordova/ns/plugins/1.0">

    <name><plugin-name-here></name>

    <js-module
            name="<plugin-name-here>"
            src="www/<plugin-name-here>.js”>
	<!--clobbers target is the name of the object that will be saved in window to call our iOS code like window.SampleIOSPlugin.echoSum—>
        <clobbers target="<window-object-name-here>" />
    </js-module>

    <platform name="ios">
        <config-file target="config.xml" parent="/*">
            <feature name="<plugin-name-here>">
                <param name="ios-package" value="<plugin-name-here>" onLoad="true" />
            </feature>
        </config-file>
        <header-file src="src/ios/<plugin-name-here>.h/>
        <source-file src="src/ios/<plugin-name-here>.m"/>
    </platform>

</plugin>

.h :

#import <Cordova/CDVPlugin.h>

@interface <plugin-name-here> : CDVPlugin{
}

- (void) echoSum:(CDVInvokedUrlCommand *) command;

@end

.m :

#import "<plugin-name-here>.h"

@implementation <plugin-name-here>

- (void) echoSum: (CDVInvokedUrlCommand *) command{

    NSNumber *variable1 = [command.arguments objectAtIndex:0];
    NSNumber *variable2 = [command.arguments objectAtIndex:1];
    int sum = variable1.intValue + variable2.intValue;
    CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:sum];
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

}

@end

.js :

var exec = require('cordova/exec');

var PLUGIN_NAME = "<plugin-name-here>";

var <plugin-name-here> = {
    echoSum: function(success,firstInt,secondInt){
        exec(success, null, PLUGIN_NAME, 'echoSum', [firstInt,secondInt]);
    }
};

module.exports = <plugin-name-here>;

Add Plugin to Cordova project :

cordova plugin add <path-to-plugin-directory OR git-clone-repo-link> --save-dev

For example:

cordova plugin add https://github.com/sahajbhaikanhaiya/SampleIOSPlugin.git --save-dev

Call our method in JavaScript :

window.<plugin-name-here>.<function-name-here>(<pass-parameters-here>);

For example:

var onSuccess = function(result){
    console.log("The sum is : " result);
};
window.SampleIOSPlugin.echoSum(onSuccess,10,20);

sampleiosplugin's People

Contributors

sahajbhaikanhaiya avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.