I am new to ionic framework
, with that AngularJS
. I have started learning and developing in Ionic framework
using Ionic ver2
(which is using AngularJS2
).
I would like to know, how to use external libraries in Ionic2? Like using cordova iBeacon
, cordova iBeacon docs.
How to structure my app so that I can write one or more generic functionality using external libs (like cordov iBeacon) and use it in my app where ever I needed (Like in different pages js).
OR - how can I include libraries required to do native hardware related actions?
Feel free to give all your thoughts and suggestions regarding this.
Many many thanks.
Finally I was able to figure out all by myself.
Step 1: Add plugin into the app
By moving into project folder through the command line, run the following line of command to add the plugin into project
sudo cordova plugin add https://github.com/petermetz/cordova-plugin-ibeacon.git
Step 2: Using the plugin in the app
make sure in plugins/fetch.json
plugin details are added:
"com.unarin.cordova.beacon": {
"source": {
"type": "git",
"url": "https://github.com/petermetz/cordova-plugin-ibeacon.git",
"subdir": "."
},
"is_top_level": true,
"variables": {}
}
And in plugins/android.json
in installed_plugins
following lines are there,
"com.unarin.cordova.beacon": {
"PACKAGE_NAME": "io.ionic.starter"
}
That's it, we start using the plugin features in any pages, in the app, by using the variable : cordova.plugins.locationManager
Example use cases:
To enable device bluetooth : cordova.plugins.locationManager.enableBluetooth();
NOTE If it is not working fine, update the plugin again. To update the
cordova-plugin-ibeacon
I firstremoved
the plugin from the app andadded again
.