getAppVersion

Read the version of the App from config.xml and make it available in js
Binarypark0.1.04
platforms: android,amazon-fireos,ubuntu,ios,blackberry10,wp7,wp8,windows8,windows,browser
$ cordova plugin add org.binarypark.cordova.plugins.version

cordova_app_version_plugin

This plugin reads the version of your app that you put in config.xml and makes it available inside your app via Javascript.

This plugin should work on any platform since it does not rely on any native code.

Changelog

  • 0.1.0
    • Added namespace version to not override other plugins see issue 2
      Call to retrieve the appVersion is now: window.cordova.plugins.version.getAppVersion()
  • 0.0.4
    • Changed directory separators from \\to / see issue 1

Installation

Cordova CLI

cordova plugin add org.binarypark.cordova.plugins.version

The plugin will then be accessable via window.cordova.plugins.version.getAppVersion().

Usage

config.xml example

<?xml version='1.0' encoding='utf-8'?>
<widget id="my.app.id" version="1.5.0">...</widget>

A call window.cordova.plugins.version.getAppVersion() will return the version "1.5.0".

How does it work?

The plugins uses the before_prepare hook to generate the getAppVersion.js file which will be added to the App on build. The getAppVersion.js file which comes with the plugin is just a placeholder, as it should be available when the plugin is installed.

Since getAppVersion.js is regenerated on every build, you should not add it under version control!