From babb3c285ce1cd0d8e9316c2eacdbeb8d2b76a6e Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Mon, 26 Oct 2015 23:59:42 -0700 Subject: [PATCH] CodePush.sync implementation --- CodePush.ios.js | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/CodePush.ios.js b/CodePush.ios.js index 8555e10..e26b999 100644 --- a/CodePush.ios.js +++ b/CodePush.ios.js @@ -95,12 +95,52 @@ function notifyApplicationReady() { return NativeCodePush.notifyApplicationReady(); } +function sync(options = {}) { + return new Promise((resolve, reject) => { + checkForUpdate() + .then((remotePackage) => { + if (!remotePackage) { + resolve(CodePush.SyncStatus.NO_UPDATE_AVAILABLE); + } + else { + var dialogButtons = [ + { + text: options.downloadButtonText || "Download", + onPress: () => { + remotePackage.download() + .then((localPackage) => { + resolve(CodePush.SyncStatus.APPLY_SUCCESS); + localPackage.apply(options.rollbackTImeout); + }, reject); + } + } + ]; + + if (!remotePackage.isMandatory) { + dialogButtons.push({ + text: options.cancelButtonText || "Cancel", + onPress: () => resolve(CodePush.SyncStatus.USER_CANCELLED) + }); + } + + React.AlertIOS.alert(options.title || "Update available", remotePackage.description, dialogButtons); + } + }, reject); + }); +}; + var CodePush = { getConfiguration: getConfiguration, checkForUpdate: checkForUpdate, getCurrentPackage: getCurrentPackage, notifyApplicationReady: notifyApplicationReady, - setUpTestDependencies: setUpTestDependencies + setUpTestDependencies: setUpTestDependencies, + sync: sync, + SyncStatus: { + NO_UPDATE_AVAILABLE: 0, + APPLY_SUCCESS: 1, + USER_CANCELLED: 2 + } }; -module.exports = CodePush; +module.exports = CodePush; \ No newline at end of file