Search code examples
javascriptcordovaphonegap-pluginscordova-pluginsphonegap

Cordova/Phonehap - get app version number from config.xml


I know there are a lot of topics on this issue but none of them seem to have the solution I need.

In this framework7 / phonegap app where I'm working on there is this send feedback option in which I want to include the appversion. I tried a lot of plugins to get the versionnumber from the config.xml file but none of them seem to work so I might be on the wrong path.

Currently I have cordova-plugin-app-version installed and I'm trying to alert the versionnumber as a test.

$$(document).on('click', '.do-send-feedback', function(e) {
  e.preventDefault();
  cordova.getAppVersion.getVersionNumber().then(function (version) {
      alert(version);
  });
});

I've also tried (but that didn't work either):

cordova.getAppVersion.getVersionNumber(function (version) {
    alert(version);
});

The code seems to get stuck at that point and I don't know why. The plugin in installed and specified in config.xml

The only thing I did different was changing 'cordova' to ' phongegap' in the installation since otherwise it won't work. but I'm always doing it that way and never had problems with that in particular before.

Testing it on my Android device.

Anyone know how to fix this?


Solution

  • The wizUtils plugin will work for Android and iOS.

    Install it:

    cordova plugin add https://github.com/Wizcorp/phonegap-plugin-wizUtils#develop --nofetch
    

    Use it:

    document.addEventListener('deviceready', function(){
        wizUtils.getBundleVersion(function(version){
            alert("Version: " + version);
        }); 
    }, false);