// App version 1 (current version)
var onError = function (error) {
console.log("An error occurred. " + error);
};
var onInstallSuccess = function () {
console.log("Installation succeeded.");
};
var onPackageDownloaded = function (localPackage) {
// Install regular updates after someone navigates away from the app for more than 2 minutes
// Install mandatory updates after someone restarts the app
localPackage.install(onInstallSuccess, onError, { installMode: InstallMode.ON_NEXT_RESUME, minimumBackgroundDuration: 120, mandatoryInstallMode: InstallMode.ON_NEXT_RESTART });
};
var onUpdateCheck = function (remotePackage) {
if (!remotePackage) {
console.log("The application is up to date.");
} else {
// The hash of each previously reverted package is stored for later use.
// This way, we avoid going into an infinite bad update/revert loop.
if (!remotePackage.failedInstall) {
console.log("A CodePush update is available. Package hash: " + remotePackage.packageHash);
remotePackage.download(onPackageDownloaded, onError);
} else {
console.log("The available update was attempted before and failed.");
}
}
};
window.codePush.checkForUpdate(onUpdateCheck, onError);
//------------------------------------------------
// App version 2 (updated version)
var app = {
onDeviceReady: function () {
// Calling this function is required during the first application run after an update.
// If not called, the application will be reverted to the previous version.
window.codePush.notifyApplicationReady();
// ...
}
}