App version not showing

Hi There,

I am trying to show the App version number, and I think I set it up correctly, but nothing is shown.
This what I have done so far:

In the app.module.ts, I included:

import { AppVersion } from '@ionic-native/app-version';

Then in the same file, at the providers, added:

AppVersion

Then on the contacts.ts file, added again:

import { AppVersion } from '@ionic-native/app-version';

Then added the following:

export class ContactPage {
  contact: string = "contactus";
  versionNumber: '0.0.1';
  
  constructor(private appVersion: AppVersion,public navCtrl: NavController) {
    this.appVersion.getVersionNumber().then((version) => {
      this.versionNumber = version;
    })
  }
}

And the contact.html:

{{versionNumber}}

Am I missing something?

Did you also ionic cordova plugin add cordova-plugin-app-version to install the Cordova plugin?
How are you testing? On the device or emulator?

Yes, installed cordova and the plugin.

Testing on device.

Any idea why it’s not working.

One thing to mention is that I am using ionic 3 not ionic 2. Probably won’t matter, but still.

Create a new, blank project and add only this plugin. If it still doesn’t work there, please upload the complete project to Github and provide us with a link. Then we can debug.

(What is your ionic info ouptut by the way?)

Thanks for your reply, at the moment it already is a blank project (with tabs) and just the app-version plugin.

Ionic info shows:

global packages:

@ionic/cli-utils : 1.4.0
Cordova CLI      : 7.0.1
Ionic CLI        : 3.4.0

local packages:

@ionic/app-scripts              : 1.3.7
@ionic/cli-plugin-cordova       : 1.4.0
@ionic/cli-plugin-ionic-angular : 1.3.1
Cordova Platforms               : android 6.2.3 ios 4.4.0
Ionic Framework                 : ionic-angular 3.4.2

System:

Node       : v8.1.2
OS         : OS X El Capitan
Xcode      : Xcode 8.2.1 Build version 8C1002
ios-deploy : not installed
ios-sim    : not installed
npm        : 5.0.3

Well then, upload to Github or Bitbucket and provide the link so we can look into it.

Hereby the github link: https://github.com/udarts/test

1 Like

You uploaded something that is different from what you described in your first post:
There is no {{versionNumber}} in contact.html. (Also don’t initialize with the same value as the real value of course - how would you know if it worked or not? Changed it to 0.0.0)

When I fix these mistaked the app shows the version 0.0.1 just fine.

Hi Sujan, sorry I was trying something out but forgot to switch it back before uploading. I tried your changed, but on my iphone it is not showing. As I am using the app: ionic view to test the app, it is still blank.

Btw, I have updated the github.

Yeah, not surprising :pensive:
This is not one of the supported plugins of Ionic View: https://docs.ionic.io/tools/view/#supported-plugins

Bummer, how did you test it? In xcode? Or something else?

I just did ionic cordova run android to get it running in my local emulator and a local device.
If I were on a Mac I could execute the same with ios.

Thanks, will try it when I can

1 Like

I’ve got the same problem on a real iPhone when installed the App via Xcode.
I think it has to be a conflict with another plugin.
A similar issue with background-plugin
see

cordova-plugin-advanced-http 1.7.0 "Advanced HTTP plugin"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-background-mode 0.7.2 "BackgroundMode"
cordova-plugin-badge 0.8.5 "Badge"
cordova-plugin-calendar 4.6.0 "Calendar"
cordova-plugin-compat 1.2.0 "Compat"
cordova-plugin-device 1.1.6 "Device"
cordova-plugin-file 4.3.3 "File"
cordova-plugin-gyroscope 0.1.4 "Device Gyroscope"
cordova-plugin-inappbrowser 1.7.1 "InAppBrowser"
cordova-plugin-ionic-webview 1.1.16 "cordova-plugin-ionic-webview"
cordova-plugin-network-information 1.3.3 "Network Information"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.4-dev "StatusBar"
cordova-plugin-whitelist 1.3.1 "Whitelist"
cordova-sqlite-storage 2.0.4 "Cordova sqlite storage plugin"
ionic-plugin-keyboard 2.2.1 "Keyboard"
    @ionic/cli-utils  : 1.15.1
    ionic (Ionic CLI) : 3.15.1

global packages:

    cordova (Cordova CLI) : 7.0.1 

local packages:

    @ionic/app-scripts : 3.0.1
    Cordova Platforms  : ios 4.4.0
    Ionic Framework    : ionic-angular 3.7.1

System:

    Android SDK Tools : 25.2.3
    ios-deploy        : 1.9.2 
    ios-sim           : 5.0.8 
    Node              : v8.0.0
    npm               : 5.0.0 
    OS                : macOS Sierra
    Xcode             : Xcode 9.0.1 Build version 9A1004

For Ionic 4 check this tutorial

this.appVersion.getAppName().then(value => {
  this.AppName = value;
}).catch(err => {
  alert(err);
});

this.appVersion.getPackageName().then(value => {
  this.PackageName = value;
}).catch(err => {
  alert(err);
});

this.appVersion.getVersionCode().then(value => {
  this.VersionCode = value;
}).catch(err => {
  alert(err);
});

this.appVersion.getVersionNumber().then(value => {
  this.VersionNumber = value;
}).catch(err => {
  alert(err);
});

the plugin is working perfectly, just put the code after the platform is ready , like this:
this.platform.ready().then(() => {
this.appVersion.getVersionNumber().then((version)=>{
console.log(version);
});
});