Check Ionic App new version

Hi
I am looking for a way to show the user an Ionic popup if there is a new version of an Ionic app.

I will use http.post inside app.js .run section and trigger an ionic poup if there is a new version .

What i am confuse about, is how can i read a file that indicate a new version, can config.xml file provide this information ? into version atribute or id atribute of the widget xml markup ?

//Verify new version and trigger a warning
$http.post("http://www.somedomain.com/verifyVersion.php")
  .success( function(data) {
      console.log(' success data '+data);
      actualAppversion = somewhere(); //TODO: define a service that retrieve the actual version
      $scope.appVersionActual = actualAppversion;
      $scope.appNewVersion  = data;
      if($scope.appNewVersion!= $scope.appVersionActual){
        $ionicPopup.confirm({title: "You have an old version",content: "A new version is available."})
      }
})
.error(function(error){
  console.log('Had an error'+error);
})

Hey,

You can try with this plugin, I’ve never used this before, but it seems to fit your goal.

Also available on ngCordova:

http://ngcordova.com/docs/plugins/appVersion/

1 Like

Trying to figure out why i did not get the version

I do install the plugin, and follow https://blog.nraboy.com/2014/11/find-application-version-ionic-framework-app/ post

Window.cordova is always undefined and did not get the version.

I declare a variable outside the module :

var appVersion = "0.0.0";

    .run(function($ionicPlatform, $ionicPopup) {
      $ionicPlatform.ready(function() {
        if (window.cordova && window.cordova.plugins.Keyboard) {
          cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
          cordova.plugins.Keyboard.disableScroll(true);
    
  cordova.getAppVersion(function(version) {
            alert("window.cordova.plugins.Keyboard"+window.cordova);
            alert("window.cordova.plugins.Keyboard"+window.cordova.plugins.Keyboard);
            appVersion = version
            alert('appVersion : '+appVersion);
            console.log('appVersion : '+appVersion);
            $ionicPopup.confirm({title: "Version", content: "appVersion : "+appVersion })
          });
    
        }

Are you testing only in the browser ? Have you already tried it on the emulator/device ? There are certain plugins that will work in the browser, as said here

No i am testing on device with Android 4.1.2. Seems my problem is cordova being undefined, so cordova.getAppVersion will follow this undefined state.

Creating a blank app from scratch just work´s . Some javascript must be in conflict with cordova.js

1 Like