如果Playstore中有任何更新版本,我需要显示更新应用程序的消息。如何获取代码以了解应用程序是否已更新?
答案 0 :(得分:1)
使用 CordovaAppVersion 功能和 IonicPopUp
Firebase作为数据库,其中设置了状态标志和版本值,可以由管理员根据Playstore上的任何最新版本的应用程序进行审核
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();
}
}]
});
}