Created
January 21, 2020 22:33
-
-
Save aalonzolu/beb12ac359c5e7adf7336663a8d5b45b to your computer and use it in GitHub Desktop.
Cordova/Phonegap/Ionic1 Custom update with AppCenter CodePush
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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