2
votes

Trying this plugin from git hub here: cordova-plugin-app-version installed ok via Cordova Cli and used example usage as given by developr on his git hub page - since im not using a 'promise' based language then he suggests this syntax:

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

});

Not getting anything, no errors or output. Has anyone else had any luck with this plugin??

I have: Cordova version: 6.1.1 - Using with phoneGap desktop but intstalled via the cordova cli to the plugins directory ok. Added the correct line in config.xml thus : <plugin name="cordova-plugin-app-version" version="0.1.8"/>

Thanks ...

2
correct usage are already mentioned on GitHub, and check whether above code is being called or not?Nitishkumar Singh
Please put the given function in the 'onDeviceReady' event of the cordova, the above code in the question cordova.getAppVersion.getVersionNumber(function (version) { alert(version); }); is working proper for me when i put this code in 'onDeviceReady'HardikDG

2 Answers

2
votes

Make sure you have the version number specified in your mobile project. In the config.xml. See examples here. Verify in your config.xml you have version, android-versionCode, or ios-CFBundleVersion attributes on the global widget node.

Also make sure you're making all your calls within onDeviceReady.

document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady(){
    cordova.getAppVersion.getVersionNumber(function (version) {

    });
}
1
votes

Have tried out in device running on Android Marshamallow, Cordova 6.1.1, cordova android 5.1.1. The plugin works fine and i m able to get the app version using both jquery and non jquery based approach as mentioned in the plugin documentation. The code is as follows, .

index.html

<html>
    <head>
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>Version Checker</title>
    </head>
    <body>              
        Get Version(jQuery based) <input type="button" value="Version" name="version" id="version"/><br>
        Get Version <input type="button" value="Version" name="version" id="version1"/><br>     
        <script type="text/javascript" src="js/jquery.js"></script> 
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/app.js"></script>
    </body>
</html> 


app.js

$(document).ready(function() {
    document.addEventListener("deviceready", onDeviceReady, false);
});

function onDeviceReady() {  
    $('#version').click (function() {
        cordova.getAppVersion.getVersionNumber().then(function (version) {
            alert('verion(jQuery based)' + version);
        });
    });

    $('#version1').click (function() {
        cordova.getAppVersion.getVersionNumber(function (version) {
            alert("version - " + version);
        });
    });
}