Ionic 4 | Get App Version Name, Version Code and Package Name Using Ionic Native Plugin

In Ionic Application, we may need application related information like Application Name, Package Name, Version Code and Version Number. As some of these are dynamic and change every time we create a build of the production version, so it becomes difficult to manually manage these values.

This information gives a user information about the current version and control user experience if there is an update available. In Ionic we can get these values dynamically using a Cordova plugin, it enables Ionic Native applications to fetch current version name and code.

Here we will create an Ionic 4 Application to demonstrate Ionic Native’s App Version Plugin.

Let’s get started!

First, we will create a new Ionic 4 Application

Make sure you have NodeJS and latest version of Ionic CLI installed

Run the following command to create a new Ionic 4 Application

Install the Cordova and Ionic Native plugins

 

Import native plugins in app.module.ts

After imports and adding, providers for added plugins file will look like this

 

After adding AppVersion in app’s module, we will use this plugin in our Home Component.

In home.page.ts, we will define four variables of respective types and call App Version methods as below:

 

Application Name

Returns the name of the app, e.g.: “My Awesome App”

 

Package Name

Returns the package name of the app, e.g.: “com.example.myawesomeapp”

 

Version Code

Returns the build identifier of the app. In iOS a string with the build version like “1.6095” In Android a number generated from the version string, like 10203 for version “1.2.3”

 

Version Number

Returns the version of the app, e.g.: “1.2.3”

 

So our complete component can be seen as a whole:

Run your application in the real device.

We will get application related information using Cordova and Ionic Native plugin cordova-plugin-app-version. This will enable to get Application related info very quickly.

Leave a Reply

avatar
  Subscribe  
Notify of