Expo Integration

React-Native 0.60+ and Expo 43+ are requires.

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

Then add the plugin to your app configuration file :

app.json or app.config.js
{
  "expo": {
    ...,
    "plugins": [
      [
        "@batch.com/react-native-plugin",
        {
          "androidApiKey": "YOUR_ANDROID_BATCH_API_KEY",
          "iosApiKey": "YOUR_IOS_BATCH_API_KEY",
          "enableDoNotDisturb": false // Optionnal (default: false)
        }
      ]
    ]
  }
}

Additional Android steps

Copy your google-services.json file at the root of your project (get it from the Firebase Console) and link it in your app configuration file.

app.json or app.config.js
{
  "expo": {
    ...,
    "android": {
      ...,
      "googleServicesFile": "./google-services.json"
    },
  }
}

Create or adapt the react-native.config.js file at the root of your project:

react-native.config.js
module.exports = {
  dependencies: {
    '@batch.com/react-native-plugin': {
      platforms: {
        android: {
          packageInstance: 'new RNBatchPackage(this.getApplication())',
        },
      },
    },
  },
}

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.

// If you are using Batch plugin < 7.0.0 please use the following method or update the plugin.
// BatchPush.registerForRemoteNotifications();

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

Was this helpful?