From 8b5b8eab0abc4a3488455dd0a969928fb9015607 Mon Sep 17 00:00:00 2001 From: Marc <32849820+marc-whil@users.noreply.github.com> Date: Fri, 29 Jun 2018 04:30:18 -0400 Subject: [PATCH] Expose clearUpdates method to RN for purging downloaded packages (#1269) This is useful when changing to a deployment with an older version than the currently installed package. --- CodePush.js | 1 + .../codepush/react/CodePushNativeModule.java | 5 +++++ docs/api-js.md | 2 ++ ios/CodePush/CodePush.m | 12 ++++++++++-- typings/react-native-code-push.d.ts | 6 ++++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CodePush.js b/CodePush.js index 81f0a3f..645d4e6 100644 --- a/CodePush.js +++ b/CodePush.js @@ -542,6 +542,7 @@ if (NativeCodePush) { sync, disallowRestart: RestartManager.disallow, allowRestart: RestartManager.allow, + clearUpdates: NativeCodePush.clearUpdates, InstallMode: { IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java index 4ad7701..2d5e54e 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java @@ -587,4 +587,9 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule { CodePushUtils.log(e); } } + + @ReactMethod + public void clearUpdates() { + mCodePush.clearUpdates(); + } } diff --git a/docs/api-js.md b/docs/api-js.md index ba084cd..acf92c0 100644 --- a/docs/api-js.md +++ b/docs/api-js.md @@ -28,6 +28,8 @@ When you require `react-native-code-push`, the module object provides the follow * [sync](#codepushsync): Allows checking for an update, downloading it and installing it, all with a single call. Unless you need custom UI and/or behavior, we recommend most developers to use this method when integrating CodePush into their apps +* [clearUpdates](#clearupdates): Clear all downloaded CodePush updates. This is useful when switching to a different deployment which may have an older release than the current package. + #### codePush ```javascript diff --git a/ios/CodePush/CodePush.m b/ios/CodePush/CodePush.m index c6075dd..b0a8b97 100644 --- a/ios/CodePush/CodePush.m +++ b/ios/CodePush/CodePush.m @@ -209,8 +209,6 @@ static NSString *bundleResourceSubdirectory = nil; [CodePushConfig current].deploymentKey = deploymentKey; } -#pragma mark - Test-only methods - /* * WARNING: This cleans up all downloaded and pending updates. */ @@ -221,6 +219,8 @@ static NSString *bundleResourceSubdirectory = nil; [self removeFailedUpdates]; } +#pragma mark - Test-only methods + /* * This returns a boolean value indicating whether CodePush has * been set to run under a test configuration. @@ -867,6 +867,14 @@ RCT_EXPORT_METHOD(restartApp:(BOOL)onlyIfUpdateIsPending resolve(@(NO)); } +/* + * This method clears CodePush's downloaded updates. + * It is needed to switch to a different deployment if the current deployment is more recent. + */ +RCT_EXPORT_METHOD(clearUpdates) { + [CodePush clearUpdates]; +} + #pragma mark - JavaScript-exported module methods (Private) /* diff --git a/typings/react-native-code-push.d.ts b/typings/react-native-code-push.d.ts index 8df9f78..fa43625 100644 --- a/typings/react-native-code-push.d.ts +++ b/typings/react-native-code-push.d.ts @@ -273,6 +273,12 @@ declare namespace CodePush { */ function disallowRestart(): void; + /** + * Clear all downloaded CodePush updates. + * This is useful when switching to a different deployment which may have an older release than the current package. + */ + function clearUpdates(): void; + /** * Immediately restarts the app. *