<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sangkhim Khun on Medium]]></title>
        <description><![CDATA[Stories by Sangkhim Khun on Medium]]></description>
        <link>https://medium.com/@sangkhim?source=rss-4807d69342ef------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*JQM5HIJVPfy__TqR.jpg</url>
            <title>Stories by Sangkhim Khun on Medium</title>
            <link>https://medium.com/@sangkhim?source=rss-4807d69342ef------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 06:04:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sangkhim/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Build your first Cordova plugin for Ionic Native]]></title>
            <link>https://medium.com/@sangkhim/build-your-first-cordova-plugin-for-ionic-native-38d29a170145?source=rss-4807d69342ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/38d29a170145</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[apache-cordova]]></category>
            <category><![CDATA[ionic-native]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Sangkhim Khun]]></dc:creator>
            <pubDate>Mon, 06 Nov 2017 15:17:01 GMT</pubDate>
            <atom:updated>2020-02-04T13:22:16.459Z</atom:updated>
            <content:encoded><![CDATA[<ol><li><strong>Create IONIC project</strong></li></ol><pre>ionic start ionic-how-to-create-cordova-plugin blank</pre><p><strong>2. Create Cordova plugin using </strong><a href="https://cordova.apache.org/docs/en/latest/plugin_ref/plugman.html"><strong>plugman</strong></a></p><pre>cd ionic-how-to-create-cordova-plugin</pre><pre>mkdir plugins_src<br>cd plugins_src</pre><pre>plugman create <br>  --name HelloWorld<br>  --plugin_id cordova-plugin-hello-world<br>  --plugin_version 0.0.1</pre><pre>cd HelloWorld</pre><pre>plugman platform add --platform_name android<br>plugman platform add --platform_name ios</pre><p>Create package.json:</p><pre>plugman createpackagejson .</pre><p>Answer the questions presented, and you will end up with a package.json that looks like this:</p><pre>{<br>  &quot;name&quot;: &quot;HelloWorld&quot;,<br>  &quot;version&quot;: &quot;0.0.1&quot;,<br>  &quot;description&quot;: &quot;HelloWorld&quot;,<br>  &quot;cordova&quot;: {<br>    &quot;id&quot;: &quot;cordova-plugin-hello-world&quot;,<br>    &quot;platforms&quot;: [<br>      &quot;android&quot;,<br>      &quot;ios&quot;<br>    ]<br>  },<br>  &quot;keywords&quot;: [<br>    &quot;ecosystem:cordova&quot;,<br>    &quot;cordova-android&quot;,<br>    &quot;cordova-ios&quot;<br>  ],<br>  &quot;author&quot;: &quot;Sangkhim&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;<br>}</pre><p>Add plugin to the project:</p><pre>cd ..<br>cd ..</pre><pre>ionic cordova plugin add plugins_src/HelloWorld</pre><p><strong>3. Call plugin in IONIC (without Ionic Native)</strong></p><pre>declare var cordova: any;</pre><pre>var success = function(result) {<br>  alert(JSON.stringify(result, undefined, 2));<br>}</pre><pre>var failure = function(result) {<br>  alert(JSON.stringify(result, undefined, 2));<br>}</pre><pre>cordova.plugins.HelloWorld.coolMethod({<br>  _sMessage: &quot;Hello World&quot;<br>}, success, failure);</pre><p><strong>4. Create </strong><a href="https://ionicframework.com/docs/native/"><strong>Ionic Native</strong></a><strong> to wrap Cordova plugin</strong></p><p>Checkout: <br><a href="https://github.com/ionic-team/ionic-native/">https://github.com/ionic-team/ionic-native/</a></p><pre>npm install<br>npm install <a href="http://twitter.com/ionic">@ionic</a>-native/core --save<br>npm install --global gulp-cli</pre><pre>mkdir <a href="http://twitter.com/ionic">@ionic</a>-native<br>gulp plugin:create -n <a href="http://twitter.com/ionic">@ionic</a>-native/HelloWorld</pre><p>Edit File:<br><a href="http://twitter.com/ionic">@ionic</a>-native/src/@ionic-native/plugins/hello-world</p><blockquote>Promise Style</blockquote><pre>import { Plugin, Cordova, IonicNativePlugin } from &#39;@ionic-native/core&#39;;<br>import { Injectable } from &#39;@angular/core&#39;;</pre><pre>@Plugin({<br>  pluginName: &#39;HelloWorld&#39;,<br>  plugin: &#39;cordova-plugin-hello-world&#39;,<br>  pluginRef: &#39;cordova.plugins.HelloWorld&#39;, <br>  repo: &#39;&#39;, <br>  platforms: [&#39;Android&#39;, &#39;iOS&#39;],<br>  install: &#39;&#39;, <br>})<br>@Injectable()<br>export class HelloWorld extends IonicNativePlugin {<br>  @Cordova({<br>    successIndex : 1,<br>    errorIndex : 2<br>  })<br>  coolMethod(options: {}): Promise&lt;any&gt; {<br>    return;<br>  }<br>}</pre><blockquote>Observable Style</blockquote><pre>import { Plugin, Cordova, IonicNativePlugin } from &#39;@ionic-native/core&#39;;<br>import { Injectable } from &#39;@angular/core&#39;;<br>import { Observable } from &#39;rxjs/Observable&#39;;</pre><pre>@Plugin({<br>  pluginName: &#39;HelloWorld&#39;,<br>  plugin: &#39;cordova-plugin-hello-world&#39;,<br>  pluginRef: &#39;cordova.plugins.HelloWorld&#39;, <br>  repo: &#39;&#39;, <br>  platforms: [&#39;Android&#39;, &#39;iOS&#39;],<br>  install: &#39;&#39;, <br>})<br>@Injectable()<br>export class HelloWorld extends IonicNativePlugin {<br>  @Cordova({<br>    successIndex : 1,<br>    errorIndex : 2,<br>    observable: true<br>  })<br>  coolMethod(options: HelloWorldOptions): Observable&lt;any&gt; {<br>    return;<br>  }<br>}<br>export interface HelloWorldOptions {<br>  _sMessage: string;<br>}</pre><p>Build:</p><pre>cd ionic-native<br>npm run build hello-world</pre><p>Install:</p><pre>cd ionic-how-to-create-cordova-plugin<br>npm install --save <a href="http://twitter.com/ionic">@ionic</a>-native/hello-world</pre><p><strong>5. Call plugin in IONIC (with Ionic Native)</strong></p><p>app.module.ts</p><pre>import { HelloWorld } from &#39;@ionic-native/hello-world&#39;;</pre><pre>providers: [<br>  ...<br>  HelloWorld,<br>  ...<br>]</pre><p>home.ts</p><pre>import { HelloWorld } from &#39;@ionic-native/hello-world&#39;;</pre><pre>constructor(..., public helloWorld: HelloWorld) {</pre><pre>}</pre><blockquote>Promise Style</blockquote><pre>this.helloWorld.coolMethod({<br>  _sMessage: &quot;Hello World&quot;<br>}).then((result) =&gt; {<br>  alert(JSON.stringify(result, undefined, 2));<br>}, (err) =&gt; {<br>  alert(JSON.stringify(err, undefined, 2));<br>});</pre><blockquote><em>Observable Style</em></blockquote><pre><strong>const</strong> watch <strong>= </strong>this.helloWorld.coolMethod({<br>  _sMessage: &quot;Hello World&quot;<br>}).subscribe((result) =&gt; {<br>  alert(JSON.stringify(result, undefined, 2));<br>}, (err) =&gt; {<br>  alert(JSON.stringify(err, undefined, 2));<br>});</pre><pre>watch.unsubscribe();</pre><h3><strong>Reference:</strong></h3><ul><li><a href="https://github.com/ionic-team/ionic-native/blob/master/DEVELOPER.md">ionic-team/ionic-native</a></li><li><a href="https://play.google.com/store/apps/developer?id=sangkhim">Android Apps by sangkhim on Google Play</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38d29a170145" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>