The official React Native plugin for the Batch SDK. Made with ❤️ by BAM and Batch.
yarn add @bam.tech/react-native-batch
npm i @bam.tech/react-native-batch
/ios
pod init
pod 'Batch', '~>1.13'
to your Podfilepod install
If you don’t use CocoaPods, you can integrate Batch SDK manually.
{your-project}/ios/Batch
{your-project}/ios/Batch
react-native version | link the plugin |
---|---|
>= 0.60.0 |
- auto-linking is supported |
< 0.60.0 |
- From the root folder |
react-native link @bam.tech/react-native-batch
|// android/build.gradle
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:4.3.4'
}
}
// android/app/build.gradle
dependencies {
implementation platform('com.google.firebase:firebase-bom:25.12.0')
implementation "com.google.firebase:firebase-messaging"
...
}
apply plugin: 'com.google.gms.google-services'
// android/app/build.gradle
defaultConfig {
...
resValue "string", "BATCH_API_KEY", "%YOUR_BATCH_API_KEY%"
}
/android/app
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>
In AppDelegate.m
, start Batch:
#import "RNBatch.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[RNBatch start:false]; // or true if you want the do not disturb mode
...
return YES;
}
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);
}
Author: bamlab
Demo: https://bamlab.github.io/react-native-batch-push/
Source Code: https://github.com/bamlab/react-native-batch-push
#react-native #react #mobile-apps