# Expo Integration

*Expo 54+ and Batch-React-Native v12 are required.*

The Batch React-Native Plugin can be integrated with Expo in bare and managed workflow, but it cannot be used thought the Expo Go app because this last doesn't support custom native code.

### Installation

Start installing the `Batch-React-Native-Plugin` with the package manager of your choice:

{% tabs %}
{% tab title="Yarn" %}

```sh
yarn add @batch.com/react-native-plugin //v12+ required
```

{% endtab %}

{% tab title="NPM" %}

<pre class="language-python"><code class="lang-python"><strong>npm install @batch.com/react-native-plugin
</strong></code></pre>

{% endtab %}
{% endtabs %}

Then install the the `Batch-Expo-Plugin`:

```
npx expo install @batch.com/expo-plugin
```

### Configure

Then add the plugin to your app configuration file :

{% code title="app.json or app.config.js" %}

```json
{
  "expo": {
    ...,
    "plugins": [
      [
        "@batch.com/expo-plugin",
        {
          "androidApiKey": "YOUR_ANDROID_BATCH_API_KEY",
          "iosApiKey": "YOUR_IOS_BATCH_API_KEY",
        }
      ]
    ]
  }
}
```

{% endcode %}

#### Configuration options

<table><thead><tr><th width="272.5859375">Key</th><th width="254.71875">Description</th><th width="80.04296875">Type</th><th width="78.3125">Default</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td><code>iosApiKey</code></td><td>Your Batch iOS Api key</td><td>string</td><td>/</td><td>true</td></tr><tr><td><code>androidApiKey</code></td><td>Your Batch Android Api key</td><td>string</td><td>/</td><td>true</td></tr><tr><td><code>enableDoNotDisturb</code></td><td>Whether Batch should start in "do not disturb" (DnD) mode, or not.</td><td>boolean</td><td>false</td><td>false</td></tr><tr><td><code>enableDefaultOptOut</code></td><td>Whether Batch should be opted-out by default</td><td>boolean</td><td>false</td><td>false</td></tr><tr><td><code>enableProfileCustomIDMigration</code></td><td>Whether Batch should automatically identify logged-in user when running the SDK v2 for the first time.</td><td>boolean</td><td>true</td><td>false</td></tr><tr><td><code>enableProfileCustomDataMigration</code></td><td>Whether Batch should automatically attach current installation's data to the User's Profile when running the SDK v2 for the first time</td><td>boolean</td><td>true</td><td>false</td></tr><tr><td><code>androidSmallIconResourceId</code></td><td>The android small notification icon resource id. eg: "@drawable/push_icon"</td><td>string</td><td>/</td><td>false</td></tr><tr><td><code>androidNotificationsColor</code></td><td>The push notification accent color (You should pass an aRGB integer, eg: #ffff2189). </td><td>string</td><td>/</td><td>false</td></tr><tr><td><code>enableIOSRichNotifications</code></td><td>Wether Batch should enable the rich push notifications on iOS</td><td>boolean</td><td>false</td><td>false</td></tr></tbody></table>

### Enable push notifications

Add the following in your app code, ideally the first view a user sees when opening the app:

```js
import { BatchPush } from '@batch.com/react-native-plugin'

// Ask for the permission to display notifications
BatchPush.requestNotificationAuthorization()
// Or use the async variant
// const granted = await BatchPush.requestNotificationAuthorizationAsync()

// iOS ONLY:
// Using the above method, the push token will automatically be fetched by the SDK.

// Alternatively, you can call requestNotificationAuthorization later
// But, you should always refresh your token on each application start
// This will make sure that even if your user's token changes, you still get notifications
// BatchPush.refreshToken();
```

### Build and run locally

Once the plugin is installed you will need to run the `expo prebuild --clean` command to rebuild the app with the plugin changes.

Then you can run your application with `expo run:android` or `expo run:ios`.

### Build with EAS

When you are ready to go to production or to provide a new development client (for internal testing) containing your newly added custom native code: [build your app with custom native code with EAS](https://docs.expo.dev/workflow/customizing/#releasing-apps-with-custom-native-code-to)

You will have to register every iOS device you plan on testing on with `eas device:create` (it has to be done before the build)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.batch.com/developer/sdk/react-native/sdk-integration/expo-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
