Skip to content

Instantly share code, notes, and snippets.

@aalonzolu
Created January 21, 2020 22:33
Show Gist options
  • Save aalonzolu/beb12ac359c5e7adf7336663a8d5b45b to your computer and use it in GitHub Desktop.
Save aalonzolu/beb12ac359c5e7adf7336663a8d5b45b to your computer and use it in GitHub Desktop.
Cordova/Phonegap/Ionic1 Custom update with AppCenter CodePush
let onSyncStatusChange = function(status) {
switch (status) {
case SyncStatus.CHECKING_FOR_UPDATE:
// Show "Checking for update" notification
console.log('checking for update');
break;
case SyncStatus.AWAITING_USER_ACTION:
// Show "Checking for update" notification
console.log('AWAITING_USER_ACTION');
break;
case SyncStatus.DOWNLOADING_PACKAGE:
// Show "downloading" notification
console.log("Descargando...");
break;
case SyncStatus.INSTALLING_UPDATE:
// Show "installing" notification
console.log("Instalando...")
break;
case SyncStatus.ERROR:
console.log("¡Uy! Ocurrió un error. No se preocupe, la aplicación se actualizará más tarde.");
break;
case SyncStatus.UPDATE_INSTALLED:
console.log("Aplicación actualizada con éxito");
break;
case SyncStatus.UPDATE_IGNORED:
console.log("¡UH oh! Parece que ha ignorado la actualización. Actualice la próxima vez con seguridad.");
break;
}
};
let updateDialogOptions = {
updateTitle: "Actualización disponible",
optionalUpdateMessage: "Una nueva actualización de la aplicación está disponible. ¿Instalar?",
optionalIgnoreButtonLabel: "No ahora",
optionalInstallButtonLabel: "Instalar"
};
var onDownloadProgress = function(downloadProgress) {
if (downloadProgress) {
let progressval = parseInt((parseInt(downloadProgress.receivedBytes) / parseInt(downloadProgress.totalBytes)) * 100);
console.log("Downloading " + downloadProgress.receivedBytes + " of " + downloadProgress.totalBytes, progressval);
}
};
codePush.sync(onSyncStatusChange, {
updateDialog: updateDialogOptions,
installMode: InstallMode.IMMEDIATE
}, onDownloadProgress);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment