> ## Documentation Index
> Fetch the complete documentation index at: https://patch.codemagic.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Applying updates

> Control when downloaded OTA bundles become active with install modes, mandatory apply timing, and UX hook points.

After Patch downloads an update, install mode controls when that bundle becomes active. Non-mandatory releases wait for the condition set in `installMode`. Mandatory releases (published with `--mandatory`) use `mandatoryInstallMode` instead and do not wait for that looser timing.

For when the app checks and downloads updates, see [Checking for updates](/docs/setup/checking-for-updates).

  <TabItem value="react-native" label="React Native">

If you use `Patch.wrap(App, options)`, put the install options shown below in that wrapper call. The `sync()` examples are for direct integrations; adding a separate call does not configure the wrapper.

  </TabItem>
  <TabItem value="capacitor" label="Capacitor">

Pass the install options below to `start()`, or to `sync()` if you call it directly. Options passed to a separate `sync()` call do not change the options `start()` uses.

  </TabItem>
</SdkTabs>

## Install modes

`installMode` sets when a non-mandatory release becomes active: the client waits for restart, background, or resume (see table). Mandatory releases skip that path and use `mandatoryInstallMode` instead (default: `IMMEDIATE`).

| Install mode | When the new bundle becomes active |
| --- | --- |
| `ON_NEXT_RESTART` | Next cold start *(default `installMode`)* |
| `ON_NEXT_SUSPEND` | When the app goes to background after `minimumBackgroundDuration` |
| `ON_NEXT_RESUME` | When the app returns to foreground after `minimumBackgroundDuration` |
| `IMMEDIATE` | As soon as install finishes *(default `mandatoryInstallMode`)* |

`ON_NEXT_RESTART` is the default `installMode` and works well for Staging, where developers restart the app on purpose. In Production, an update applying on restart can cause unwanted behavior. `ON_NEXT_SUSPEND` is a common `installMode` for Production: the bundle activates when the user backgrounds the app after `minimumBackgroundDuration`, without interrupting an open session.

  <TabItem value="react-native" label="React Native">

```ts

void sync({
  installMode: InstallMode.ON_NEXT_SUSPEND,
  mandatoryInstallMode: InstallMode.IMMEDIATE,
  minimumBackgroundDuration: 60_000, // ms; for ON_NEXT_RESUME / ON_NEXT_SUSPEND
});
```

  </TabItem>
  <TabItem value="capacitor" label="Capacitor">

```ts

start({
  installMode: InstallMode.ON_NEXT_SUSPEND,
  mandatoryInstallMode: InstallMode.IMMEDIATE,
  minimumBackgroundDuration: 60_000, // ms; for ON_NEXT_RESUME / ON_NEXT_SUSPEND
});
```

Activating an update reloads the WebView with the new web assets. The plugin detects foreground and background transitions natively, so `ON_NEXT_RESUME` and `ON_NEXT_SUSPEND` work without another plugin. On iOS, opening Notification Center also moves the app out of the foreground briefly; set `minimumBackgroundDuration` to ignore short interruptions.

  </TabItem>
</SdkTabs>

### `minimumBackgroundDuration`

For `ON_NEXT_RESUME` and `ON_NEXT_SUSPEND`, Patch only activates a pending update if the app was in the background for at least this many milliseconds. That avoids restarting someone who briefly switched to another app.

Does not change behavior for `ON_NEXT_RESTART` or `IMMEDIATE`.

## Different behavior per deployment

Sync and apply behavior is client-side. The server does not push different `sync()` rules per deployment.

Teams can map Staging and Production to different app builds (different deployment keys baked into native config), then branch `sync()` options on the same build-time signal that selects the deployment key:

  <TabItem value="react-native" label="React Native">

```ts

// Wire this to whatever selects your Staging deployment key at build time:
// a build flavor / scheme, or a build-time env flag (e.g. react-native-config).
declare function isStagingBuild(): boolean;

void sync(
  isStagingBuild()
    ? {
        installMode: InstallMode.ON_NEXT_RESTART,
        mandatoryInstallMode: InstallMode.IMMEDIATE,
      }
    : {
        installMode: InstallMode.ON_NEXT_SUSPEND,
        mandatoryInstallMode: InstallMode.ON_NEXT_RESUME,
        minimumBackgroundDuration: 300_000, // 5 min
      },
);
```

This matches the common pattern: `ON_NEXT_RESTART` in Staging, `ON_NEXT_SUSPEND` in Production.

  </TabItem>
  <TabItem value="capacitor" label="Capacitor">

```ts

// Wire this to whatever selects your Staging deployment key at build time:
// a build-time env flag, or the environment that generates capacitor.config.ts.
declare function isStagingBuild(): boolean;

start(
  isStagingBuild()
    ? {
        installMode: InstallMode.ON_NEXT_RESTART,
        mandatoryInstallMode: InstallMode.IMMEDIATE,
      }
    : {
        installMode: InstallMode.ON_NEXT_SUSPEND,
        mandatoryInstallMode: InstallMode.ON_NEXT_RESUME,
        minimumBackgroundDuration: 300_000, // 5 min
      },
);
```

This matches the common pattern: `ON_NEXT_RESTART` in Staging, `ON_NEXT_SUSPEND` in Production.

  </TabItem>
</SdkTabs>

## Mandatory updates

Publishing with `--mandatory` (CLI or dashboard) marks a release mandatory on the server. Eligible clients install it under `mandatoryInstallMode` rather than waiting for `installMode` conditions.

On the client, `mandatoryInstallMode` controls when that apply happens (default: `IMMEDIATE`, as soon as the download finishes).

You can toggle mandatory on an existing release with `cmpatch release patch` or `promote` with no new app binary required. See [Production control](/docs/using-patch/production-control).

:::info
If a device skipped an older mandatory release, a later compatible update may still be treated as mandatory until the user catches up.
:::

## UX hook points

Patch does not ship built-in prompts, splash transitions, or update dialogs. Your app decides the UX.

Common hook points:

- `sync()` result (`"update-installed"`, `"up-to-date"`, `"error"`) to decide whether to show messaging
- progress callback (`receivedBytes`, `totalBytes`) for progress UI
- `checkForUpdate()` + `remotePackage.releaseNotes` for "update available" text
- `isNextVersionReady()` for "Update ready" while the current bundle keeps running
- `disallowRestart()` / `allowRestart()` to avoid restarts during critical flows

For button-driven flows (check now, download now, apply now), see [Manual control](/docs/setup/manual-control).

### Splash screen timing

If you apply updates around app launch, treat splash behavior as app UX policy:

- defer apply to next restart/resume for less disruptive startup
- or keep splash visible while checking/downloading when fast-first-update UX matters more

Patch exposes install timing and restart controls; your app owns the splash implementation details.

## Blocking restarts during critical UX

`disallowRestart()` prevents Patch from programmatically reloading the JS bundle (including after `IMMEDIATE` installs) until `allowRestart()` runs. Typical pattern: block during checkout or onboarding, allow when the flow completes.

  <TabItem value="react-native" label="React Native">

```ts

disallowRestart();
// … critical flow …
allowRestart(); // may flush a queued restart
```

  </TabItem>
  <TabItem value="capacitor" label="Capacitor">

```ts

disallowRestart();
// … critical flow …
allowRestart(); // may flush a queued restart
```

  </TabItem>
</SdkTabs>

Alternatively, prefer `ON_NEXT_RESTART` and call `restartApp()` only when your app knows it is safe. `disallowRestart` is for global `sync()` calls where you still need a no-interruption window.

## Summary

| Goal | Primary API |
| --- | --- |
| Less intrusive apply timing | `installMode`, `minimumBackgroundDuration` |
| Critical fixes without waiting for install conditions | Server `--mandatory`; client `mandatoryInstallMode` |
| No restart during checkout, etc. | `disallowRestart` / `allowRestart` |
| Full control over each step | [Manual control](/docs/setup/manual-control) |
