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.
This commit is contained in:
Marc
2018-06-29 04:30:18 -04:00
committed by Nickolay Toropov
parent 3144c91601
commit 8b5b8eab0a
5 changed files with 24 additions and 2 deletions

View File

@@ -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

View File

@@ -587,4 +587,9 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule {
CodePushUtils.log(e);
}
}
@ReactMethod
public void clearUpdates() {
mCodePush.clearUpdates();
}
}

View File

@@ -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

View File

@@ -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)
/*

View File

@@ -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.
*