Ionic 5 Check App Version Name, Code and Package Name Using Ionic Native Plugin
In this Ionic 5/4 tutorial, we’ll learn How to check application version code and name, application package id using the Cordova and Ionic Native plugin. Also, we will discuss how to change the version of the Ionic application for the next production release. In the Ionic application, we may need application-related information like Application Name,…
In this Ionic 5/4 tutorial, we’ll learn How to check application version code and name, application package id using the Cordova and Ionic Native plugin. Also, we will discuss how to change the version of the Ionic application for the next production release.
In the Ionic application, we may need application-related information like Application Name, Package Name/ID, Version Code, and Version Number.
As some of these values related to the application are dynamic and change every time we create a build for production, it becomes difficult to manually manage these values.
This 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 and Native plugins, it enables Ionic applications to fetch current version name and code.
Here we will create an Ionic Application to demonstrate Ionic Native’s App Version Plugin.
Let’s get started!
Install or Update Ionic CLI
To create Ionic applications, you need to install @ionic/cli package. If already have updated it to the latest version
$ npm install -g @ionic/cli
Create new Ionic Angular Application
We’ll create a new Ionic 5 application using Angular framework with a starter blank template.
Next, we need to import the AppVersion class in the App Module to make its methods accessible in the application components.
Open the app.module.ts file, import the AppVersion class then add in the providers array
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { AppVersion } from '@ionic-native/app-version/ngx';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [
StatusBar,
SplashScreen,
AppVersion,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule {}
Getting App Version and Other Information
After adding AppVersion in the app’s module, we will use this plugin in our Home Component.
Update Home Component
In the home.page.ts class file, we will define four variables to save values returned from methods of AppVersion class
The getVersionCode() 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”
Now we’ll discuss how to change the current version of Ionic application to release in productions. To update the Application executable file like APK for Android we need to update the version code.
To change it open the config.xml file at the project root folder.
On the first tag <widget> you will see some important values related to the application like
id="io.ionic.starter" : The application package name/ ID.
version="0.0.1" : This is the version code that you need to change to “0.0.2” for example to release for next version on production or play store.
The <name>MyApp</name>is shown on the mobile screen after the installs your application.
The <author> tag having author-related information.
Conclusion
This is how we can get app-related information dynamically like Application Version Code, Package ID/Name, etc by installing the App Version naive plugin.
This can be useful to display the Application’s current version in About section or check if current version of application is the latest one or not to display the update application message inside the application.
You can check this post to update the application by directly downloading the APK file for Android application without leaving the application using Native plugin.
Please share your feedback. Thanks for reading…
Hi, I’m Jolly. I am passionate about creating web applications and problem solving. With over 8+ years of experience in web development, I love building intuitive interfaces and finding creative solutions.
In my free time, I’m always learning new languages and frameworks to stay on top of the latest trends. I hope my tutorials can help others on their web development journey.
Leave a Reply