IONIC2 Cordova Plugins

IONIC2 | Using cordova plugins in ionic2 apps

abba Ionic2, Mobile App Leave a Comment

Use Cordova Plugins to extend your IONIC2 Apps.

This post uses the Ionic CLI Version: 2.2.1, so make sure to update to the latest version of Ionic2 as follows. Add the sudo keyword if the following installation fails.

For this post I am going to use the Cordova plugin cordova-plugin-apteligent. This specific cordova plugin is NOT part of ionic-native. Apteligent provides several key features that could help you gain insights about your mobile application. Some of the reasons I use this plugin are :

  • Track userflow through out application
  • Crash Reporting (Exceptions)
  • Logging User Metadata

You can start by installing the cordova plugin with the ionic plugin add command as follows:

It is best to use ionic plugin add command instead of cordova plugin add command. The ionic command uses the cordova command under the hood. Once the plugin is added, you should see a new folder cordova-plugin-apteligent under the plugins folder. To be able to access the plugin in your .ts files you have to declare a variable as follows:

Once you have the cordova variable declared, you are ready to begin using the plugin in your .ts file. I am using the apteligent plugin as follows:

Thats it. Apteligent is initialized and will start recording your app’s data. You can add apteligent code in various places in your mobile as you deem necessary. You can use this approach to use cordova plugins that are not included in ionic-native. Using cordova plugins included in ionic-native is pretty straightforward and does not involve declaring a cordova variable.

Other articles of interest