getVersionNumber () returns me undefined in Ionic

0

I need to check the application version for 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 inside the alert is returned undefined.

In my config.xml, the version is populated 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">
    
asked by anonymous 15.08.2018 / 15:20

2 answers

1

You're trying to show a value that has not yet returned in promisse , you need to put alert in the right place:

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

In addition, it's important to check if the plugin is properly installed and referenced, see more here: ionicframework.com/docs / native / app-version

    
15.08.2018 / 15:26
1

Include the 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.

    
15.08.2018 / 15:28