...
Code Block |
---|
Mapp.engage(sdkKey: string, googleProjectId: string, server: string, appID: string, tenantID: string);
const App = () => {
...
} |
@param {string} sdkID - The SDK ID for your account.
@param {string} googleProjectID - The Google project id from your Firebase console for the chosen app.
@param {string} server - The Server, which will be used for engagement, this info will be provided by account managers.
@param {string} tenantID - The ID which recognizes you at the Mapp Engage system, will be also provided by account managers.
...
L3
L3_US
EMC
EMC_US
CROC
Check if the plugin is initialized
Code Block |
---|
const ready = await Mapp.isReady(); |
Check if the device is registered in Mapp
Code Block | ||
---|---|---|
| ||
const registered = await Mapp.isDeviceRegistered().then(data => { //do something with data }; |
Alias
Get device alias
Code Block | ||
---|---|---|
| ||
Mapp.getAlias().then(datalet alias => { console.log(data); Alert.alert(data) });await Mapp.getAlias(); |
Set device alias
Code Block |
---|
Mapp.setAlias(”some alias”) |
...
Get device info
Code Block | ||
---|---|---|
| ||
Mapp.getDeviceInfo().then(datalet deviceInfo => { console.log(data); Alert.alert(data) });await Mapp.getDeviceInfo(); |
Push API
Push Enabled
Check if the feature is enabled.
Code Block | ||
---|---|---|
| ||
Mapp.isPushEnabled().then(datalet enabled => { console.log(data); Alert.alert(data.toString())await Mapp.isPushEnabled(); |
Push toggle
Disable or enable push.
Code Block | ||
---|---|---|
| ||
await Mapp.setPushEnabled(true) |
...
false); // disable
await Mapp.setPushEnabled(false); // enable |
Push messages event
Push message events are triggered when a push message is received, opened, dismissed, or when a silent push message is received.
Subscribe/listen for push received events:
Code Block |
---|
Mapp.addPushListener(pushMessage => {
console.log(JSON.stringify(pushMessage));
Alert.alert('Push message event', JSON.stringify(pushMessage));
}); |
For iOS also is an available listener for rich messages:
Code Block |
---|
Mapp.addRichMessagesListener((notification) => {
console.log(JSON.stringify(notification));
Alert.alert(JSON.stringify(notification))
}); |
For iOS also is an available listener for rich messages:
Code Block |
---|
Mapp.addRichMessagesListener((notification) => |
Setup for push message handling from React Native plugin
For a use-cases where clients needs to handle push messages on their own, or when using some additional push service (besides MAPP), then some additional setup needs to be done.
Android setup
Multiple firebase services can not exist in the same aplication, it will rise conflicts and unpredictable behaviour. So, we need to disable default service from Mapp native part.
Open android folder and update the AndroidManifest.xml file:
Code Block |
---|
<service android:name=".MessageService"
android:exported="false"
tools:node="remove">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service> |
After that we disabled the default Mapp service for receiving and handling push messages, we need to provide another service for push messages. This can be done in 2 ways.
Native implementation
We can create in the native part, our service that will extend MessageService, and implement the required functionality.
Code Block |
---|
public class MyMessageService extends MappMessagingService { @Override public void console.log(JSON.stringify(notification))onCreate() { super.onCreate(); } Alert.alert(JSON.stringify(notification)) @Override public void onMessageReceived(RemoteMessage remoteMessage) { if(remoteMessage.getData().containsKey("p")) { // handle Mapp push messages super.onMessageReceived(remoteMessage); }else{ // handle your own push messages } } @Override public void onNewToken(String s) { super.onNewToken(s); |
Check if received push message is from MAPP.
@param{RemoteMessage} remoteMessage - message received from firebase messaging service.
Code Block |
---|
Mapp.isPushFromMapp(remoteMessage).then(isMapp =>{ console.log(isMapp); } // subscribe on your own service with firebase token } } |
Info |
---|
Every overridden method must call the super method in order for the underlying plugin works correctly. |
React native implementation
For this way of handling push messages, we can use react native plugins:
Code Block |
---|
# Install & setup the app module
yarn add @react-native-firebase/app
# Install the messaging module
yarn add @react-native-firebase/messaging |
For complete instructions on how to use the plugins above and install them, please visit the official documentation: https://rnfirebase.io/messaging/usage
After we have successfully completed the setup of the app and messaging plugins, we only need to forward Mapp’s push messages to the Mapp plugin:
Code Block |
---|
import FBMessaging from '@react-native-firebase/messaging';
...
const handleFirebasePushMessage = async (remoteMessage) => {
let isFromMapp = await Mapp.isPushFromMapp(remoteMessage);
if(isFromMapp){
Mapp.setRemoteMessage(remoteMessage);
}else{
// handle push messages from other services
}
};
...
// to recevive and handle push messages when application is in a background/quit state
FBMessaging().setBackgroundMessageHandler(handleFirebasePushMessage);
// to receive and handle push messages when application is in a foreground state
FBMessaging().onMessage(handleFirebasePushMessage); |
and also needs to forward Firebase device token
Code Block |
---|
const token = await FBMessaging().getToken();
Mapp.setToken(token); // forward Firebase token to a Mapp plugin |
Check if received push message is from MAPP.
@param{RemoteMessage} remoteMessage - message received from firebase messaging service.
Code Block |
---|
let isFromMapp = await Mapp.isPushFromMapp(remoteMessage); |
Provide firebase token to the Mapp SDK. It’s used for registring device for receiving push messages from Mapp.
@param{String} token - token generated from Firebase Messaging instance.
Code Block |
---|
Mapp.setToken(token); |
Pass received firebase message to the Mapp SDK.
@param{RemoteMessage} remoteMessage - message received from firebase messaging service.
...