如何从Playstore获取应用程序的更新版本号?-IONIC

时间:2015-11-10 17:46:57

标签: angularjs ionic

如果Playstore中有任何更新版本,我需要显示更新应用程序的消息。如何获取代码以了解应用程序是否已更新?

1 个答案:

答案 0 :(得分:1)

Cordova设备插件

  

使用 CordovaAppVersion 功能和 IonicPopUp

     
    

Firebase作为数据库,其中设置了状态标志版本值,可以由管理员根据Playstore上的任何最新版本的应用程序进行审核

  

a busy cat

    document.addEventListener("deviceready", function () {

    $cordovaAppVersion.getVersionNumber()
        .then(function (version) {
            var appVersion = version;
            var starCount = firebase.database().ref("version");

            starCount.once('value').then(function(snapshot) {
                if(snapshot.val().ver!=appVersion&&snapshot.val().status===1)
                {
                    versionerr(snapshot.val().ver,appVersion);
                    $ionicPlatform.registerBackButtonAction(function(e) {
                        //This will restrict the user to close the popup by pressing back key
                         e.preventDefault();
                    },401);
                };
            });
        }); 
    }, false);

versionerr = function(newv,oldv){

    var myPopup = $ionicPopup.show({
        title: "Update Available",
        template: "A newer version("+n`enter code here`ewv+") of this app is available for download. Please update it from PlayStore ! ",
        subTitle: 'current version : '+oldv,
        scope: $scope,
        buttons: [{ 
            text: 'Exit',
            type: 'button-dark',
            onTap: function(e) {     
                ionic.Platform.exitApp();
            }
        }, {
            text: '<b>Update</b>',
            type: 'button-positive',
            onTap: function(e) {

            $window.open("https://play.google.com/store/apps/details?id=com.ionicframework.hostelcordova596017", '_system');
                ionic.Platform.exitApp();
            }  
        }]
    });
}