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:

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

Then install the the Batch-Expo-Plugin:

npx expo install @batch.com/expo-plugin

Configure

Then add the plugin to your app configuration file :

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

Configuration options

Key
Description
Type
Default
Required

iosApiKey

Your Batch iOS Api key

string

/

androidApiKey

Your Batch Android Api key

string

/

enableDoNotDisturb

Whether Batch should start in "do not disturb" (DnD) mode, or not.

boolean

false

enableDefaultOptOut

Whether Batch should be opted-out by default

boolean

false

enableProfileCustomIDMigration

Whether Batch should automatically identify logged-in user when running the SDK v2 for the first time.

boolean

true

enableProfileCustomDataMigration

Whether Batch should automatically attach current installation's data to the User's Profile when running the SDK v2 for the first time

boolean

true

androidSmallIconResourceId

The android small notification icon resource id. eg: "@drawable/push_icon"

string

/

androidNotificationsColor

The push notification accent color (You should pass an aRGB integer, eg: #ffff2189).

string

/

Enable push notifications

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

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

// Ask for the permission to display notifications
BatchPush.requestNotificationAuthorization()

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

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)

Last updated