Hello Readers,
In today's post we will learn about to get app information using ionic2 and typescript. First of all we need to install plugin through CLI:
$ ionic plugin add cordova-plugin-app-version
This plugin supports Android and iOS platform. By using this plugin we can get app version, app name, app package name, app version code.
To import the plugin you need to use from 'ionic-native' package.
import { AppVersion } from 'ionic-native';
There are some methods to get app information which are as follows:
home.html
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding class="home">
<button (click) = "onClick()">click</button>
{{appName}}
</ion-content>
home.ts:
import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import { AppVersion } from 'ionic-native';
@Component({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
appName;
onClick()
{
AppVersion.getAppName().then((s) => {
this.appName = s;
})
}
constructor(private navController: NavController) {
}
}
home.html
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding class="home">
<button (click) = "onClick()">click</button>
{{packageName}}
</ion-content>
home.ts:
import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import { AppVersion } from 'ionic-native';
@Component({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
packageName;
onClick()
{
AppVersion.getPackageName().then((s) => {
this.packageName = s;
})
}
constructor(private navController: NavController) {
}
}
- To get app version number:
home.html
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding class="home">
<button (click) = "onClick()">click</button>
{{versionNumber}}
</ion-content>
home.ts:
import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import { AppVersion } from 'ionic-native';
@Component({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
versionNumber;
onClick()
{
AppVersion.getVersionNumber().then((s) => {
this.versionNumber = s;
})
}
constructor(private navController: NavController) {
}
}
You can use these methods to get respective information. Hope this will help you :)
1 Comment(s)