getVersionNumber() returns me Undefined on Ionic

Asked

Viewed 43 times

0

I need to check the application version to make validations, the problem is that the promisse getVersionNumber() is returning me Undefined.

I tried something like:

ngOnInit(): void {
    let versaoApp;
    this.appVersion.getVersionNumber().then(version => {
      versaoApp = version;
    });

    this.dialogs.alert(versaoApp);

But within Alert is returned Undefined.

In my config.xml, the version is filled in as follows:

<widget id="idapp" version="0.0.4" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

2 answers

1


Are you trying to show a value that has not yet returned on promise, need to put the alert in the right place:

 this.appVersion.getVersionNumber().then(version => {
      versaoApp = version;
      this.dialogs.alert(versaoApp);
    });

Also, it is important to check if the plugin is installed and referenced correctly, see more here: ionicframework.com/Docs/Native/app-version

1

Include Alert within the function. As it stands, it may be responding before checking the version.

ngOnInit(): void {
  let versaoApp;
  this.appVersion.getVersionNumber().then(version => {
    versaoApp = version;
    this.dialogs.alert(versaoApp);
  });

Also make sure you’re testing on IOS or Android.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.