Reputation: 1205
I am very new to ionic development. I have an Objective C code that provides some custom functionality using the Camera and I want to use this native code in my ionic app using Cordova. After spending a few hours in the research I concluded that we need to create a Cordova plugin upload it on Github and then add it to our Ionic project. I tried I few demos and read some articles but all seem to be out of date and I am not able to proceed.
It would be really great if someone could guide me with
Any help would really be appreciated.
Upvotes: 1
Views: 1451
Reputation: 61
Most information should be contained on the related Cordova website. Here are some boiled down leads ... Use cordova-plugman to create a cordova plugin like so:
npm i -g git+https://[email protected]/apache/cordova-plugman.git
plugman create --name "test" --plugin_id "test" --plugin_version "0.0.1"
plugman createpackagejson .
plugman platform add --platform_name "android"
This should get you setup with a default plugin. To use the plugin from a Cordova app, change the directory to the app and run:
cordova plugin add /absolute/path/to/plugin
In the config.xml
of the plugin, inside the following tag, you can specify how the plugin should be accessed during runtime.
<js-module name="test" src="www/test.js"><clobbers target="cordova.plugins.test" /></js-module>
In this case, the file www/test.js
will be available under window.cordova.plugins.test
. Reference is the Cordova documentation for the plugin.xml
. Additional information on how to access native code on iOS can be found in the Cordova documentation for iOS plugin development.
Upvotes: 6