SlideShare a Scribd company logo
Cordova
iOS Native Plugin
Development
MOBILE APP DEVELOPMENT FOR WEB DEVELOPERS.
JOSUE BUSTOS
Artist, Software Developer
@hozwe
npmjs.com/package/cordova-plugin-base64binary
https://www.behance.net/hozwe
https://www.linkedin.com/in/josuebustos
Follow me on…
Plugin development for iOS
 Xcode IDE
 iOS Device (recommended)
 iOS simulator
 Some familiarity with writing Objective-C code.
 Some experience implementing Cocoa Touch API’s.
 Cordova CLI must be installed.
 Cordova Plugman must be installed.
 A machine with Mac OSX installed.
Some Items you will need to get started for iOS native plugin development.
Configuring your plugin project
 plugin.xml
 The JavaScript interface
 Objective-C source code
 package.json
 Publish your plugin
Creating a plugin project
Open terminal window and type in the following text. You can copy paste the text here into
your terminal and modify it.
plugman create --name testPlugin --plugin_id cordova-
plugin-openwith --plugin_version 0.0.1 --path
/Users/myname/Desktop/firstplugin
Sample generated plugin project
plugin.xml starter
<?xml version="1.0" encoding="UTF-8"?> <plugin
xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-device"
version="0.2.3">
<name>Device</name>
<description>Your plugin description</description>
<license>Your license 2.0</license>
<keywords>Your, Plugin, Is, Unique</keywords>
<js-module src="www/testPlugin.js" name="device”>
<clobbers target=”Plugin" /></js-module>
</plugin>
iOS platform-specific
<platform name="ios">
<config-file target="config.xml" parent="/*”>
<feature name=”Echo">
<param name="ios-package" value=”Echo"/>
</feature>
</config-file>
<header-file src="src/ios/TestPlugin.h" />
<source-file src="src/ios/TestPlugin.m" />
</platform>
The JavaScript interface
// in your www/testPlugin.js plugin project
window.echo = function(str, callback) {
cordova.exec(callback, function(err) {
callback('Nothing to echo.'); },
"Echo",
"echo",
[str]
);
};
// in your www/index.js development project.
window.echo("echome", function(echoValue) {
alert(echoValue == "echome"); // should alert true.
});
Objective-C plugin class
/********* TestPlugin.h Cordova Plugin Header *******/
#import <Cordova/CDVPlugin.h>
@interface
Echo : CDVPlugin
- (void) echo:(CDVInvokedUrlCommand*)command;
@end
/********* TestPlugin.m Cordova Plugin Implementation *******/
#import ”TestPlugin.h" #import <Cordova/CDVPlugin.h>
@implementation Echo - (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
Create package.json
Copy paste the text below into your terminal and press enter. This will create a
package.json file into your root directory of your plugin project. Learn more about why this
file is needed on the cordova blog.
plugman createpackagejson /path/to/your/plugin
Sample package.json
{
name: "cordova-plugin-yourpluginname",
version: ”0.0.1 ",
description: ”Description of your plugin goes here",
cordova:
{
id: "cordova-plugin-yourpluginname",
platforms:
[“ios”]
},
repository:
{
type: "git",
url: "https://github.com/Joewsh/cordova-plugin-yourpluginname"
},
keywords:
["cordova”,”sample”,"ecosystem:cordova”,"cordova-ios”],
"author": {
"name": ”Your Name", "email": ”your@email.com", "url": "http://yourwebsite.com"
},
"license": "MIT",
"bugs": {
"url": “https://github.com/username/cordova-plugin-yourpluginname/isues"
},
"homepage": https://github.com/username/cordova-plugin-yourpluginname#readme
}
Final plugin project
Testing your plugin
To test your plugin type out or copy paste the text into your terminal and press return. You
can modify the command to specify your native environment.
NOTE: While testing, plugins must be installed in the platform specific directory. See next
slide for example.
plugman install --platform ios –project
/path/to/your/app/platforms/ios --plugin
/path/to/my/plugin
A test app
project with a
test plugin
installed.
Publish your plugin to NPM
// Enter the command below if you never published to the NPM
registry.
npm adduser
// Enter the command below after adding a user successfully
// you can also reuse this command to update your plugin
npm publish /path/to/your/plugin
// that’s it!!
After hours of debugging your native plugin and making sure it works in various scenarios.
You can now publish it to the NPM registry using the terminal command below.
Need help?
 Cordova Plugin Development Guide
 What else can Apache Cordova do?

More Related Content

PDF
Modern Web Applications Utilizing HTML5 (Dev Con TLV 06-2013)
PPT
Phone gap android plugins
PDF
Introduction to phone gap
PDF
Google app engine development with java and php
PDF
Tutorial: Develop Mobile Applications with AngularJS
PDF
Getting Your Hooks into Cordova
PDF
Getting your Hooks into Cordova
PDF
Getting started with .net on openSUSE (asp.net with c#)
Modern Web Applications Utilizing HTML5 (Dev Con TLV 06-2013)
Phone gap android plugins
Introduction to phone gap
Google app engine development with java and php
Tutorial: Develop Mobile Applications with AngularJS
Getting Your Hooks into Cordova
Getting your Hooks into Cordova
Getting started with .net on openSUSE (asp.net with c#)

What's hot (20)

PDF
webpack 101 slides
PDF
node-webkit : Make a magic from your a desktop app to desktop app!
PDF
Cross-platform Desktop application with AngularJS and build with Node-webkit
ODP
Passo a Passo para criar uma aplicação Móvel Híbrida
ODP
Considerations with Writing JavaScript in your DotNetNuke site
PDF
Grunt, Gulp & fabs: Build Systems and Development-Workflow for Modern Web-App...
ODP
iOS Developers Conference-iOS Automation with Cucumber, Appium and Saucelabs
ODP
Packaging DNN extensions
PPTX
Jenkins Plugin Development With Gradle And Groovy
PDF
Writing a Jenkins / Hudson plugin
PDF
Introduction to Google Chrome Extensions Development
PPTX
Bringing Javascript to the Desktop with Electron
PPTX
Deploy Node.js application in Heroku using Eclipse
PPTX
Gradle + Google I/O 2014 remarks
PDF
NativeScript: mobile app. no webview.
PDF
Modern web applications
PPTX
2. auto deploy to tomcat on jenkins
PDF
Workshop - Golang language
PDF
ITB2019 CommandBox vs Node.js - Nolan Erck
PDF
Welcome to Jenkins
webpack 101 slides
node-webkit : Make a magic from your a desktop app to desktop app!
Cross-platform Desktop application with AngularJS and build with Node-webkit
Passo a Passo para criar uma aplicação Móvel Híbrida
Considerations with Writing JavaScript in your DotNetNuke site
Grunt, Gulp & fabs: Build Systems and Development-Workflow for Modern Web-App...
iOS Developers Conference-iOS Automation with Cucumber, Appium and Saucelabs
Packaging DNN extensions
Jenkins Plugin Development With Gradle And Groovy
Writing a Jenkins / Hudson plugin
Introduction to Google Chrome Extensions Development
Bringing Javascript to the Desktop with Electron
Deploy Node.js application in Heroku using Eclipse
Gradle + Google I/O 2014 remarks
NativeScript: mobile app. no webview.
Modern web applications
2. auto deploy to tomcat on jenkins
Workshop - Golang language
ITB2019 CommandBox vs Node.js - Nolan Erck
Welcome to Jenkins
Ad

Similar to Cordova iOS Native Plugin Development (20)

PPT
Apache Cordova phonegap plugins for mobile app development
PDF
Apache Cordova 4.x
PPTX
Introduction to Apache Cordova (Phonegap)
PDF
iOS App Using cordova
PDF
[2015/2016] Apache Cordova
PDF
Cordova 101
PDF
Apache cordova
PDF
Apache Cordova
PPTX
Wrapping with PhoneGap
PDF
Cordova: APIs and instruments
PPTX
[ApacheCon 2016] Advanced Apache Cordova
PDF
Top Cordova Challenges and How to Tackle Them
PPTX
PhoneGap Day 2016 USA
PDF
Cordova + Ionic + MobileFirst
PPTX
Building Cross-Platform JavaScript Apps using Cordova
PPTX
NCDevCon 2017 - Cross Platform Mobile Apps
PDF
Building Cross-Platform Mobile Apps
PDF
PhoneGap/Cordova
PPTX
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
PDF
Introduction to Cordova
Apache Cordova phonegap plugins for mobile app development
Apache Cordova 4.x
Introduction to Apache Cordova (Phonegap)
iOS App Using cordova
[2015/2016] Apache Cordova
Cordova 101
Apache cordova
Apache Cordova
Wrapping with PhoneGap
Cordova: APIs and instruments
[ApacheCon 2016] Advanced Apache Cordova
Top Cordova Challenges and How to Tackle Them
PhoneGap Day 2016 USA
Cordova + Ionic + MobileFirst
Building Cross-Platform JavaScript Apps using Cordova
NCDevCon 2017 - Cross Platform Mobile Apps
Building Cross-Platform Mobile Apps
PhoneGap/Cordova
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Introduction to Cordova
Ad

Recently uploaded (20)

PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PDF
Approach and Philosophy of On baking technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
NewMind AI Weekly Chronicles - August'25 Week I
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Machine learning based COVID-19 study performance prediction
Understanding_Digital_Forensics_Presentation.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
20250228 LYD VKU AI Blended-Learning.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Electronic commerce courselecture one. Pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
Approach and Philosophy of On baking technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
NewMind AI Weekly Chronicles - August'25 Week I
The AUB Centre for AI in Media Proposal.docx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
“AI and Expert System Decision Support & Business Intelligence Systems”
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Cordova iOS Native Plugin Development

  • 1. Cordova iOS Native Plugin Development MOBILE APP DEVELOPMENT FOR WEB DEVELOPERS.
  • 4. Plugin development for iOS  Xcode IDE  iOS Device (recommended)  iOS simulator  Some familiarity with writing Objective-C code.  Some experience implementing Cocoa Touch API’s.  Cordova CLI must be installed.  Cordova Plugman must be installed.  A machine with Mac OSX installed. Some Items you will need to get started for iOS native plugin development.
  • 5. Configuring your plugin project  plugin.xml  The JavaScript interface  Objective-C source code  package.json  Publish your plugin
  • 6. Creating a plugin project Open terminal window and type in the following text. You can copy paste the text here into your terminal and modify it. plugman create --name testPlugin --plugin_id cordova- plugin-openwith --plugin_version 0.0.1 --path /Users/myname/Desktop/firstplugin
  • 8. plugin.xml starter <?xml version="1.0" encoding="UTF-8"?> <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-device" version="0.2.3"> <name>Device</name> <description>Your plugin description</description> <license>Your license 2.0</license> <keywords>Your, Plugin, Is, Unique</keywords> <js-module src="www/testPlugin.js" name="device”> <clobbers target=”Plugin" /></js-module> </plugin>
  • 9. iOS platform-specific <platform name="ios"> <config-file target="config.xml" parent="/*”> <feature name=”Echo"> <param name="ios-package" value=”Echo"/> </feature> </config-file> <header-file src="src/ios/TestPlugin.h" /> <source-file src="src/ios/TestPlugin.m" /> </platform>
  • 10. The JavaScript interface // in your www/testPlugin.js plugin project window.echo = function(str, callback) { cordova.exec(callback, function(err) { callback('Nothing to echo.'); }, "Echo", "echo", [str] ); }; // in your www/index.js development project. window.echo("echome", function(echoValue) { alert(echoValue == "echome"); // should alert true. });
  • 11. Objective-C plugin class /********* TestPlugin.h Cordova Plugin Header *******/ #import <Cordova/CDVPlugin.h> @interface Echo : CDVPlugin - (void) echo:(CDVInvokedUrlCommand*)command; @end /********* TestPlugin.m Cordova Plugin Implementation *******/ #import ”TestPlugin.h" #import <Cordova/CDVPlugin.h> @implementation Echo - (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
  • 12. Create package.json Copy paste the text below into your terminal and press enter. This will create a package.json file into your root directory of your plugin project. Learn more about why this file is needed on the cordova blog. plugman createpackagejson /path/to/your/plugin
  • 13. Sample package.json { name: "cordova-plugin-yourpluginname", version: ”0.0.1 ", description: ”Description of your plugin goes here", cordova: { id: "cordova-plugin-yourpluginname", platforms: [“ios”] }, repository: { type: "git", url: "https://github.com/Joewsh/cordova-plugin-yourpluginname" }, keywords: ["cordova”,”sample”,"ecosystem:cordova”,"cordova-ios”], "author": { "name": ”Your Name", "email": ”your@email.com", "url": "http://yourwebsite.com" }, "license": "MIT", "bugs": { "url": “https://github.com/username/cordova-plugin-yourpluginname/isues" }, "homepage": https://github.com/username/cordova-plugin-yourpluginname#readme }
  • 15. Testing your plugin To test your plugin type out or copy paste the text into your terminal and press return. You can modify the command to specify your native environment. NOTE: While testing, plugins must be installed in the platform specific directory. See next slide for example. plugman install --platform ios –project /path/to/your/app/platforms/ios --plugin /path/to/my/plugin
  • 16. A test app project with a test plugin installed.
  • 17. Publish your plugin to NPM // Enter the command below if you never published to the NPM registry. npm adduser // Enter the command below after adding a user successfully // you can also reuse this command to update your plugin npm publish /path/to/your/plugin // that’s it!! After hours of debugging your native plugin and making sure it works in various scenarios. You can now publish it to the NPM registry using the terminal command below.
  • 18. Need help?  Cordova Plugin Development Guide  What else can Apache Cordova do?