Skip to content
CodeOnAir
Docs menu

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#

APIWhat 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.restoredScreenStateWith restoreScreen: the screen state from before a CodePush restart, else undefined.

Sync options#

OptionDefault
installModeON_NEXT_RESTART (IMMEDIATE, ON_NEXT_RESUME, ON_NEXT_SUSPEND also available)
mandatoryInstallModeIMMEDIATE
updateDialogoff — pass true or { title, optionalUpdateMessage, … }
ignoreFailedUpdatestrue — skip updates this device rolled back
minimumBackgroundDuration0 — seconds in the background before ON_NEXT_RESUME / ON_NEXT_SUSPEND restart
checkFrequencyON_APP_START (wrapper only; ON_APP_RESUME, MANUAL)
restoreScreenfalse (wrapper only) — bring the user back to the same screen after a CodePush restart
deploymentKeyfrom strings.xml / Info.plist

Sync statuses#

SyncStatusMeaning
CHECKING_FOR_UPDATEAsking the server.
AWAITING_USER_ACTIONThe update dialog is showing.
DOWNLOADING_PACKAGEDownloading — onProgress reports bytes.
INSTALLING_UPDATEInstalling.
UP_TO_DATENothing new for this app version.
UPDATE_INSTALLEDInstalled; runs per the install mode.
UPDATE_IGNOREDThe user declined, or this device rolled the update back before.
SYNC_IN_PROGRESSAnother sync is already running.
UNKNOWN_ERRORSomething 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),
);
Stuck? Write to support@codeonair.com with your App ID and what you tried — we reply within a working day.