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

Commit 8b5b8ea

Browse files
marc-whilNickToropov
authored andcommitted
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.
1 parent 3144c91 commit 8b5b8ea

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

CodePush.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ if (NativeCodePush) {
542542
sync,
543543
disallowRestart: RestartManager.disallow,
544544
allowRestart: RestartManager.allow,
545+
clearUpdates: NativeCodePush.clearUpdates,
545546
InstallMode: {
546547
IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately
547548
ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart

android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,4 +587,9 @@ public void downloadAndReplaceCurrentBundle(String remoteBundleUrl) {
587587
CodePushUtils.log(e);
588588
}
589589
}
590+
591+
@ReactMethod
592+
public void clearUpdates() {
593+
mCodePush.clearUpdates();
594+
}
590595
}

docs/api-js.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ When you require `react-native-code-push`, the module object provides the follow
2828

2929
* [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
3030

31+
* [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.
32+
3133
#### codePush
3234

3335
```javascript

ios/CodePush/CodePush.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ + (void)setDeploymentKey:(NSString *)deploymentKey
209209
[CodePushConfig current].deploymentKey = deploymentKey;
210210
}
211211

212-
#pragma mark - Test-only methods
213-
214212
/*
215213
* WARNING: This cleans up all downloaded and pending updates.
216214
*/
@@ -221,6 +219,8 @@ + (void)clearUpdates
221219
[self removeFailedUpdates];
222220
}
223221

222+
#pragma mark - Test-only methods
223+
224224
/*
225225
* This returns a boolean value indicating whether CodePush has
226226
* been set to run under a test configuration.
@@ -867,6 +867,14 @@ -(void)loadBundleOnTick:(NSTimer *)timer {
867867
resolve(@(NO));
868868
}
869869

870+
/*
871+
* This method clears CodePush's downloaded updates.
872+
* It is needed to switch to a different deployment if the current deployment is more recent.
873+
*/
874+
RCT_EXPORT_METHOD(clearUpdates) {
875+
[CodePush clearUpdates];
876+
}
877+
870878
#pragma mark - JavaScript-exported module methods (Private)
871879

872880
/*

typings/react-native-code-push.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ declare namespace CodePush {
273273
*/
274274
function disallowRestart(): void;
275275

276+
/**
277+
* Clear all downloaded CodePush updates.
278+
* This is useful when switching to a different deployment which may have an older release than the current package.
279+
*/
280+
function clearUpdates(): void;
281+
276282
/**
277283
* Immediately restarts the app.
278284
*

0 commit comments

Comments
 (0)