The official React Native plugin for the Batch SDK. Made with ❤️ by BAM and Batch.
- Install using
yarn add @bam.tech/react-native-batch
- Or
npm i @bam.tech/react-native-batch
- Go to
/ios
- If you don't have a Podfile yet run
pod init
- Add
pod 'Batch', '~>1.13'
to your Podfile - Run
pod install
If you don't use CocoaPods, you can integrate Batch SDK manually.
- Download the SDK
- Unzip the SDK
- Here instead of following the readme inside the Batch.embeddedframework folder you downloaded follow the below steps.
- Create a Batch folder in
{your-project}/ios/Batch
- Copy your Batch framework inside
{your-project}/ios/Batch
- Open your project in XCode. Right click your ".xcodeproj" and click "Add Files to {yourProjectName}…". Find the "Batch" folder you created and select it. Before clicking "Add", to the left you'll see an "Options" button. Click it, and make sure "Create Groups" and "Add to targets" for your project are both selected.
- From the root folder
- Run
react-native link @bam.tech/react-native-batch
// android/build.gradle
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:4.2.0'
}
}
// android/app/build.gradle
dependencies {
implementation "com.google.firebase:firebase-core:16.0.7"
implementation "com.google.firebase:firebase-messaging:17.3.4"
...
}
apply plugin: 'com.google.gms.google-services'
// android/app/build.gradle
defaultConfig {
...
resValue "string", "BATCH_API_KEY", "%YOUR_BATCH_API_KEY%"
}
- Add the google-services.json file to
/android/app
- In the project window
- Go to Capabilities
- Toggle Push Notifications
Go to the Batch dashboard, create an iOS app and upload your iOS push certificate.
Then, in Info.plist
, provide:
<key>BatchAPIKey</key>
<string>%YOUR_BATCH_API_KEY%</string>
import { Batch } from '@bam.tech/react-native-batch';
Batch.start();
import { BatchPush } from '@bam.tech/react-native-batch';
BatchPush.registerForRemoteNotifications();
For better results on Android 5.0 and higher, it is recommended to add a Small Icon and Notification Color. An icon can be generated using Android Studio's asset generator: as it will be tinted and masked by the system, only the alpha channel matters and will define the shape displayed. It should be of 24x24dp size. If your notifications shows up in the system statusbar in a white shape, this is what you need to configure.
This can be configured in the manifest as metadata in the application tag:
<!-- Assuming there is a push_icon.png in your res/drawable-{dpi} folder -->
<manifest ...>
<application ...>
<meta-data
android:name="com.batch.android.push.smallicon"
android:resource="@drawable/push_icon" />
<!-- Notification color. ARGB but the alpha value can only be FF -->
<meta-data
android:name="com.batch.android.push.color"
android:value="#FF00FF00" />
If you set a custom launchMode
in your AndroidManifest.xml
, add in your MainActivity.java
:
// import android.content.Intent;
// import com.batch.android.Batch;
@Override
public void onNewIntent(Intent intent)
{
Batch.onNewIntent(this, intent);
super.onNewIntent(intent);
}