How to use react-native-batch-push on android? RNBatch is undefined when trying to access RNBatch.NOTIFICATION_TYPES

Viewed 91

I'm trying to use this package in my react native project.

So far I've followed all the steps in their installation guide and I made it work on iOS.

However, on Android, every time I try to import Batch or BatchPush in my code like this:

import { BatchPush, Batch } from "@bam.tech/react-native-batch";

I get an error on Android only:

null is not an object (evaluating 'RNBatch.NOTIFICATION_TYPES')

enter image description here

So when I go to node_modules/@bam.tech/react-native-batch/dist/BatchPush.js I see this

const RNBatch = react_native_1.NativeModules.RNBatch;
exports.AndroidNotificationTypes = RNBatch.NOTIFICATION_TYPES;

So somehow the native module is not being imported correctly. Do I need to follow extra steps for this to work?

@bam.tech/react-native-batch is being used with version 5.2.1 npm version 6.14.7 react-native version 0.60.5

1 Answers

Update: it turns out that the package was not linked correctly and that I had to manually add the package in MainApplication.java (I don't know why react-native link did not add this automatically)

Add the import: import tech.bam.RNBatchPush.RNBatchPackage;

And then add new RNBatchPackage(), in the getPackages() method.

Related