Expo Integration
React-Native 0.60+ and Expo 43+ 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-pluginnpm install @batch.com/react-native-pluginThen add the plugin to your app configuration file :
{
"expo": {
...,
"plugins": [
[
"@batch.com/react-native-plugin",
{
"androidApiKey": "YOUR_ANDROID_BATCH_API_KEY",
"iosApiKey": "YOUR_IOS_BATCH_API_KEY",
"enableDoNotDisturb": false // Optionnal (default: false)
//"shouldUseNonNullableIntent": true (Only if your project is using androix.activity 1.9+).
}
]
]
}
}Since version 1.9.0 of the AndroidX Activity library, the onNewIntent signature has been modified to expect a non-nullable Intent (Intent instead of Intent?).
This change can cause a build error in your project, such as "'onNewIntent' overrides nothing." or "Argument type mismatch: actual type is 'android.content.Intent?', but 'android.content.Intent' was expected." after the expo pre-build phase.
To resolve this, please add "shouldUseNonNullableIntent": true to your app configuration file (this option will be removed in a future update.).
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.
{
"expo": {
...,
"android": {
...,
"googleServicesFile": "./google-services.json"
},
}
}Create or adapt the react-native.config.js file at the root of your project:
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

