/react-native-batch-push

React Native integration of Batch.com push notifications SDK

Primary LanguageJavaMIT LicenseMIT

React Native Batch

The official React Native plugin for the Batch SDK. Made with ❤️ by BAM and Batch.



Installation

1. Install the React Native Batch plugin

  • Install using yarn add @bam.tech/react-native-batch
  • Or npm i @bam.tech/react-native-batch

2. Setup iOS dependencies

  • 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

3. Link the plugin

  • From the root folder
  • Run react-native link @bam.tech/react-native-batch

4. Extra steps on Android

a. Install Batch dependencies

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

b. Add your Batch key

// android/app/build.gradle

defaultConfig {
    ...
    resValue "string", "BATCH_API_KEY", "%YOUR_BATCH_API_KEY%"
}

c. Add your Firebase config

  • Add the google-services.json file to /android/app

5. Extra steps on iOS

a. Enable Push Capabilities

  • In the project window
  • Go to Capabilities
  • Toggle Push Notifications

b. Configure your Batch key

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>

Usage

Start Batch

import { Batch } from '@bam.tech/react-native-batch';

Batch.start();

Enabling push notifications on iOS

import { BatchPush } from '@bam.tech/react-native-batch';

BatchPush.registerForRemoteNotifications();

Other

Small push notification icon

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

Mobile landings and in-app messaging

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);
}