SDK API
Reference for @codeonair/code-push-react-native: sync, checkForUpdate, install, notifyAppReady, restart state, sync options and sync statuses.
Most apps only need CodePush.sync(). The rest is there for custom flows — your own update screen, progress bars, or checking on demand.
Functions#
| API | What it does |
|---|---|
CodePush.sync(options, onStatus, onProgress) | Call on every launch: confirms the running update, then checks, downloads and installs. Resolves a SyncStatus. |
codePush(App) | Optional wrapper for your root component that calls sync on start (and on resume with checkFrequency). |
codePush.checkForUpdate() | A RemotePackage, or null when up to date. |
codePush.install(pkg, installMode, onProgress, options) | Download and install a package from checkForUpdate(). options: minimumBackgroundDuration. |
codePush.notifyAppReady() | Tell CodePush the update works (otherwise the next launch rolls it back). |
codePush.restartApp(onlyIfUpdateIsPending) | Restart now to run an installed update. |
codePush.getUpdateMetadata() | The running update (label, description, isFirstRun), or null on the binary. |
codePush.setRestartStateProvider(fn) | Called just before a CodePush restart; what it returns (any JSON) is kept across the restart. |
codePush.getRestoredState() | That state after a CodePush restart — once, then null. Null after a normal start or a rollback. |
codePush.trackScreenState(state) | With restoreScreen: report the current screen state (e.g. NavigationContainer's onStateChange). |
codePush.restoredScreenState | With restoreScreen: the screen state from before a CodePush restart, else undefined. |
Sync options#
| Option | Default |
|---|---|
installMode | ON_NEXT_RESTART (IMMEDIATE, ON_NEXT_RESUME, ON_NEXT_SUSPEND also available) |
mandatoryInstallMode | IMMEDIATE |
updateDialog | off — pass true or { title, optionalUpdateMessage, … } |
ignoreFailedUpdates | true — skip updates this device rolled back |
minimumBackgroundDuration | 0 — seconds in the background before ON_NEXT_RESUME / ON_NEXT_SUSPEND restart |
checkFrequency | ON_APP_START (wrapper only; ON_APP_RESUME, MANUAL) |
restoreScreen | false (wrapper only) — bring the user back to the same screen after a CodePush restart |
deploymentKey | from strings.xml / Info.plist |
Sync statuses#
| SyncStatus | Meaning |
|---|---|
CHECKING_FOR_UPDATE | Asking the server. |
AWAITING_USER_ACTION | The update dialog is showing. |
DOWNLOADING_PACKAGE | Downloading — onProgress reports bytes. |
INSTALLING_UPDATE | Installing. |
UP_TO_DATE | Nothing new for this app version. |
UPDATE_INSTALLED | Installed; runs per the install mode. |
UPDATE_IGNORED | The user declined, or this device rolled the update back before. |
SYNC_IN_PROGRESS | Another sync is already running. |
UNKNOWN_ERROR | Something failed (network, wrong key…) — the app keeps its bundle. |
Progress example#
Show download progress
codePush.sync(
{ installMode: codePush.InstallMode.IMMEDIATE },
(status) => console.log("CodePush", status),
({ receivedBytes, totalBytes }) => setProgress(receivedBytes / totalBytes),
);