Push Configuration
Android
To use Push Notification in your React Native application you need to configure Firebase into your application, refer to the Push Notification documentation to configure Push Notification in your application.
In case, your application is handling the push token registration and push payload we highly recommend you use the native Android methods(mentioned in the documentation above) for passing the token and the payload to the SDK.
If for whatever reason you wish to pass the push token and payload to the SDK via the React component/Javascript code use the below APIs
Passing Push Token
const ReactMoE = require('react-native-moengage')
// pass the push token as a string
ReactMoE.passPushToken("")
Passing Push Payload
const ReactMoE = require('react-native-moengage')
// pass the push payload as a JSONObject from FCM. Note only the data payload needs to be passed to SDK.
ReactMoE.passPushPayload({})
We highly recommend you to use the Android native APIs for passing the push payload to the MoEngage SDK instead of the React-Native/Javascript APIs. React-Native Engine might not get initialised if the application is killed or if the notification is not sent at a high priority.
iOS
APNS Certificate :
First you will have to create an APNS certificate and upload in the dashboard to be able to send push notifications in iOS. Follow the steps below to do that :
- Create an APNS certificate
- Convert resultant certificate to .pem format
- Upload .pem file to MoEngage Dashboard
*Follow the links on each step to complete it.
Adding Push Entitlement to your Project :
Once the APNS Certificate is uploaded, enable Push Entitlement in the Xcode project. For that select your app target, then go to Capabilities . Here enable the Push Notifications capability for your app as shown below :

Uninstall Tracking :
We make use of silent pushes to track uninstalls. For tracking uninstalls of all the user, enable Remote Notification background mode in app capabilities for the same as shown below :

Push Registration :
After this you will have to register for push notification by using registerForPush method of the plugin as shown below :
//This is only for iOS
const ReactMoE = require('react-native-moengage')
ReactMoE.registerForPush();
AppDelegate Remote notification methods will not be called
Plugin gets all the remote notification related callbacks, therefore you won't receive any of them in your AppDelegate. Therefore, you will have to add observers for the notifications provided by plugin instead.
Notification Click Observers:
MoEngage plugin triggers the pushClicked
event whenever a notification is clicked. This event is a common trigger for both iOS and Android platforms and is available from plugin version 5.0.0
. Refer to the below code to set listener to the same:
NOTE:
Make sure you are calling
initialize()
method of the plugin to receive these callbacks. Refer doc for more info.
import ReactMoE from 'react-native-moengage'
ReactMoE.setEventListener(
'pushClicked',
(payload) => console.log(payload)
);
Make sure this callback is set as soon as the application is initialized. Preferably in the constructor of your App.js
.
Payload
Push Payload will be received in the below format:
{
"platform": "ios/android",
"payload": {
// platform specific payload
}
}
Android Payload
All the key-value pair entered on the MoEngage Dashboard during the campaign will be available inside the payload object.
iOS Payload
Refer to this link for the iOS notification payload structure.
iOS Deprecated Events(SDK Version 1.2.0 - 4.1.0):
Make sure to use the new Events mentioned in the above section as notificationClicked
is deprecated from Plugin version 5.0.0. to have a common callback for both iOS and Android platforms. Refer to the below code to set listener to the same:
import ReactMoE from 'react-native-moengage'
ReactMoE.setEventListener(
'notificationClicked',
(notificationPayload) => console.log(notificationPayload)
);
In this case, the payload is the iOS push notification payload. Refer to this link for iOS notification payload structure.
Updated over 5 years ago