To implement this plugin quickly, add this updates object into your project.
var updates = {
getInAppUpdate: function () {
var onSuccess = function (strSuccess) {
if (strSuccess == 'UPDATE_AVAILABLE' || strSuccess == 'DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS') {
// updates.updateFlexible(); // uncomment this to show background update dialog!
updates.updateImmediate(); // uncomment this to show foreground update dialog!
}
};
var onFailure = function (strError) {
console.warn(strError);
};
cordova.plugins.InAppUpdate.getUpdateAvailability(onSuccess, onFailure);
},
updateFlexible: function () {
var onSuccess = function (strSuccess) {
console.log(strSuccess);
};
var onFailure = function (strError) {
console.warn(strError);
};
var snackbarText = "Actualización lista para instalar!"; // Translation: Update ready to install!
var snackbarButton = "REINICIAR"; // Translation: RESTART
var snackbarButtonColor = "#FF80AB";
cordova.plugins.InAppUpdate.setSnackbarOptions(onSuccess, onFailure, snackbarText, snackbarButton, snackbarButtonColor);
var onUpdateSuccess = function (strSuccess) {
console.log(strSuccess);
};
var onUpdateFailure = function (strError) {
console.warn(strError);
};
cordova.plugins.InAppUpdate.updateFlexible(onUpdateSuccess, onUpdateFailure);
},
updateImmediate: function () {
var onSuccess = function (strSuccess) {
console.log(strSuccess);
if(strSuccess == 'RESULT_CANCELED'){
console.log('User declined immediate update dialog.');
}
};
var onFailure = function (strError) {
console.warn(strError);
};
cordova.plugins.InAppUpdate.updateImmediate(onSuccess, onFailure);
}
};
To check for updates and show dialog call:
updates.getInAppUpdate();
This will show either the flexible or the immediate update dialog whenever there is a new version in Play Store.
⚠ Important
Uncomment either the updates.updateFlexible() or updates.updateImmediate() lines depending on the dialog you want to show to the end user. With flexible updates the user can keep using the app while the update is downloaded, immediate updates are immediate and the user must wait until the app is installed.
Be aware that both flexible/immediate update dialogs can be dismissed by the user, however, you can check when this happened (by evaluating if the strSuccess variable from the onSuccess function of the updateImmediate function equals "RESULT_CANCELED") and show it again to force him/her on updating the app.
To implement this plugin quickly, add this updates object into your project.
To check for updates and show dialog call:
This will show either the flexible or the immediate update dialog whenever there is a new version in Play Store.
⚠ Important
Uncomment either the
updates.updateFlexible()
orupdates.updateImmediate()
lines depending on the dialog you want to show to the end user. With flexible updates the user can keep using the app while the update is downloaded, immediate updates are immediate and the user must wait until the app is installed.Be aware that both flexible/immediate update dialogs can be dismissed by the user, however, you can check when this happened (by evaluating if the strSuccess variable from the onSuccess function of the updateImmediate function equals "RESULT_CANCELED") and show it again to force him/her on updating the app.