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

Commit babb3c2

Browse files
committed
CodePush.sync implementation
1 parent 4626f5a commit babb3c2

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

CodePush.ios.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,52 @@ function notifyApplicationReady() {
9595
return NativeCodePush.notifyApplicationReady();
9696
}
9797

98+
function sync(options = {}) {
99+
return new Promise((resolve, reject) => {
100+
checkForUpdate()
101+
.then((remotePackage) => {
102+
if (!remotePackage) {
103+
resolve(CodePush.SyncStatus.NO_UPDATE_AVAILABLE);
104+
}
105+
else {
106+
var dialogButtons = [
107+
{
108+
text: options.downloadButtonText || "Download",
109+
onPress: () => {
110+
remotePackage.download()
111+
.then((localPackage) => {
112+
resolve(CodePush.SyncStatus.APPLY_SUCCESS);
113+
localPackage.apply(options.rollbackTImeout);
114+
}, reject);
115+
}
116+
}
117+
];
118+
119+
if (!remotePackage.isMandatory) {
120+
dialogButtons.push({
121+
text: options.cancelButtonText || "Cancel",
122+
onPress: () => resolve(CodePush.SyncStatus.USER_CANCELLED)
123+
});
124+
}
125+
126+
React.AlertIOS.alert(options.title || "Update available", remotePackage.description, dialogButtons);
127+
}
128+
}, reject);
129+
});
130+
};
131+
98132
var CodePush = {
99133
getConfiguration: getConfiguration,
100134
checkForUpdate: checkForUpdate,
101135
getCurrentPackage: getCurrentPackage,
102136
notifyApplicationReady: notifyApplicationReady,
103-
setUpTestDependencies: setUpTestDependencies
137+
setUpTestDependencies: setUpTestDependencies,
138+
sync: sync,
139+
SyncStatus: {
140+
NO_UPDATE_AVAILABLE: 0,
141+
APPLY_SUCCESS: 1,
142+
USER_CANCELLED: 2
143+
}
104144
};
105145

106-
module.exports = CodePush;
146+
module.exports = CodePush;

0 commit comments

Comments
 (0)