Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Ionic2 and typescript - Plugin to return the information of the current app

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 1.96k
    Comment on it

    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:

     

    • To get app name:

    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) {
    			
    		}
    
    	}
    

     

    • To get app package name:

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: