Reputation: 1243
I put the code in place to do over the air updates, and it appears that the code does push, but every time I run:
code-push deployment ls XXXXX
I get:
Active: 0% (1 of XXX) Total: 0 (XXX pending)
The "pending" never switches to success (but I do see the app update?)
I am using an Ionic app (+Redux) have put in my app.component.ts:
platform.ready().then(() => { this.ngRedux.dispatch(update()); });
update() is in another file:
const changeUpdateStatus = status => ({
type: 'UPDATE_STATUS',
payload: status
});
export const update = () => dispatch => {
dispatch(changeUpdateStatus('INIT'));
let sync = () => {
let codePush = (<any>window).codePush;
let SyncStatus = (<any>window).SyncStatus;
if(!codePush){
throw new Error('Code push not installed');
};
const keys = {
'iOS': env.codePushKeys.ios,
'Android': env.codePushKeys.android
};
const deploymentKey = keys[(<any>window).device.platform];
console.log('Trying to sync code push using key: ', deploymentKey);
codePush.sync(
(status) => {
console.log('status:', status);
switch (status) {
case SyncStatus.UPDATE_INSTALLED:
dispatch(changeUpdateStatus('DONE'));
break;
case SyncStatus.CHECKING_FOR_UPDATE:
dispatch(changeUpdateStatus('CHECKING'));
break;
case SyncStatus.DOWNLOADING_PACKAGE:
dispatch(changeUpdateStatus('DOWNLOADING'));
break;
case SyncStatus.INSTALLING_UPDATE:
dispatch(changeUpdateStatus('INSTALLING'));
break;
default: //ERROR, UP_TO_DATE
dispatch(changeUpdateStatus('DONE'));
break;
}
},
{
deploymentKey,
installMode: (<any>window).InstallMode.IMMEDIATE,
mandatoryInstallMode: (<any>window).InstallMode.IMMEDIATE
},
(downloadProgress) => {
// TODO: Add progress to state.
if (downloadProgress) {
console.log("Downloading " + downloadProgress.receivedBytes + " of " + downloadProgress.totalBytes);
}
}
);
}
sync() && onEvent("resume").then(sync).catch( (e) => {
dispatch(changeUpdateStatus('DONE'));
analytics.logError(e);
});
};
Additional Information cordova-plugin-code-push version: 1.11.0
List of installed plugins:
<plugin name="cordova-plugin-camera" spec="^3.0.0" />
<plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
<plugin name="cordova-plugin-device" spec="^1.1.7" />
<plugin name="cordova-plugin-ionic-webview" spec="^1.1.16" />
<plugin name="cordova-plugin-contacts" spec="^3.0.0" />
<plugin name="cordova-plugin-camera-preview" spec="^0.9.0" />
<plugin name="cordova-plugin-file-transfer" spec="^1.7.0" />
<plugin name="cordova-plugin-background-upload" spec="^1.0.6" />
<plugin name="cordova-plugin-media-capture" spec="^3.0.0" />
<plugin name="cordova-sms-plugin" spec="^0.1.11" />
<plugin name="cordova-plugin-statusbar" spec="^2.4.1" />
<plugin name="cordova-plugin-code-push" spec="~1.11.0" />
<plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
<plugin name="phonegap-plugin-push" spec="^2.1.2">
<variable name="FCM_VERSION" value="11.0.1" />
</plugin>
<plugin name="cordova-android-support-gradle-release" spec="^1.2.0">
<variable name="ANDROID_SUPPORT_VERSION" value="26.+" />
</plugin>
<plugin name="cordova-plugin-globalization" spec="^1.0.7" />
<plugin name="cordova-plugin-android-permissions" spec="^1.0.0" />
Cordova version: 7.1.0
iOS/Android/Windows version: All
Does this reproduce on a debug build or release build? Yes
Does this reproduce on a simulator, or only on a physical device? Yes
Upvotes: 1
Views: 737
Reputation: 1243
Over the air updates are now working. The solution was to do a refactor and ensure that sync
is literally the FIRST thing being called. In this way, it can immediately "stamp" the build as successful when the new build starts-up.
I believe the problem was the fact that I had a bunch of code that executed prior to this (include a few API calls that may have taken a second or two).
Upvotes: 0
Reputation: 3838
This can happen when you fail to call notifyApplicationReady()
on the Code Push SDK. This method should be called somewhere near the startup of the app. It effectively reports back to Code Push that the update was successful. Without that the next time the app is started Code Push will likely trigger a rollback (depending on the details of how you deployed the update).
https://github.com/Microsoft/cordova-plugin-code-push
notifyApplicationReady: Notifies the CodePush runtime that an installed update is considered successful. If you are manually checking for and installing updates (i.e. not using the sync method to handle it all for you), then this method MUST be called; otherwise CodePush will treat the update as failed and rollback to the previous version when the app next restarts.
Upvotes: 1