Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 30b4abc

Browse files
committed
Adding more sync options
1 parent 7b27896 commit 30b4abc

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

CodePush.ios.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,34 +97,57 @@ function notifyApplicationReady() {
9797
}
9898

9999
function sync(options = {}) {
100+
var syncOptions = {
101+
ignoreFailedUpdates: true,
102+
103+
mandatoryContinueButtonLabel: "Continue",
104+
mandatoryUpdateMessage: "An update is available that must be installed",
105+
106+
optionalIgnoreButtonLabel: "Ignore",
107+
optionalInstallButtonLabel: "Install",
108+
optionalUpdateMessage: "An update is available. Would you like to install it?",
109+
110+
updateTitle: "Update available",
111+
rollbackTimeout: 0,
112+
113+
...options
114+
};
115+
100116
return new Promise((resolve, reject) => {
101117
checkForUpdate()
102118
.then((remotePackage) => {
103-
if (!remotePackage) {
119+
if (!remotePackage || (remotePackage.failedAppy && syncOptions.ignoreFailedUpdates)) {
104120
resolve(CodePush.SyncStatus.NO_UPDATE_AVAILABLE);
105121
}
106122
else {
123+
var message = null;
107124
var dialogButtons = [
108125
{
109-
text: options.updateButtonText || "Update",
126+
text: null,
110127
onPress: () => {
111128
remotePackage.download()
112129
.then((localPackage) => {
113130
resolve(CodePush.SyncStatus.APPLY_SUCCESS);
114-
localPackage.apply(options.rollbackTimeout);
131+
localPackage.apply(syncOptions.rollbackTimeout);
115132
}, reject);
116133
}
117134
}
118135
];
119136

120-
if (!remotePackage.isMandatory) {
137+
if (remotePackage.isMandatory) {
138+
message = syncOptions.mandatoryUpdateMessage;
139+
dialogButtons[0].text = syncOptions.mandatoryContinueButtonLabel;
140+
} else {
141+
message = syncOptions.optionalUpdateMessage;
142+
143+
dialogButtons[0].text = syncOptions.optionalInstallButtonLabel;
121144
dialogButtons.push({
122-
text: options.ignoreButtonText || "Ignore",
145+
text: syncOptions.optionalIgnoreButtonLabel,
123146
onPress: () => resolve(CodePush.SyncStatus.UPDATE_IGNORED)
124147
});
125148
}
126149

127-
AlertIOS.alert(options.updateTitle || "Update available", remotePackage.description, dialogButtons);
150+
AlertIOS.alert(syncOptions.updateTitle, message || remotePackage.description, dialogButtons);
128151
}
129152
}, reject);
130153
});

0 commit comments

Comments
 (0)