...
For the Initialization use method, this function should be first in your application :
Code Block | ||
---|---|---|
| ||
Mapp.engage(sdkKey: string, googleProjectId: string, server: string, appID: string, tenantID: string); const App = () => { ... } |
...
iOS uses most information from AppoxeeCofig.plist as explained in the integration section, so you need to have that plist set up inside iOS project.
Server list:
L3
L3_US
EMC
EMC_US
CROC
Check if the plugin is initialized
Code Block | ||
---|---|---|
| ||
const ready = await Mapp.isReady(); |
...
Set device alias
Code Block | ||
---|---|---|
| ||
Mapp.setAlias(”some alias”) |
...
Code Block | ||
---|---|---|
| ||
await Mapp.setPushEnabled(false); // disable await Mapp.setPushEnabled(true); // enable |
Request permission to display notification (for Android 13 and higher ONLY)
Code Block | ||
---|---|---|
| ||
let result = await Mapp.requestPostNotificationPermission();
if (result == true) {
console.log('PERMISSION GRANTED');
} else {
console.log('PERMISSION NOT GRANTED');
} |
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 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)) }); |
...
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> |
...
We can create in the native part, our service that will extend MessageService, and implement the required functionality.
Code Block | ||
---|---|---|
| ||
public class MyMessageService extends MessageService { @Override public void onCreate() { super.onCreate(); } @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); // subscribe on your own service with firebase token } } |
...
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 |
...
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 |
...
@param{RemoteMessage} remoteMessage - message received from firebase messaging service.
Code Block | ||
---|---|---|
| ||
let isFromMapp = await Mapp.isPushFromMapp(remoteMessage); |
...
@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.
Code Block | ||
---|---|---|
| ||
Mapp.setRemoteMessage(remoteMessage); |
...
@param{boolean} pushEnabled
- while logging out sets push the state
Code Block | ||
---|---|---|
| ||
Mapp.logOut(pushEnabled) |
Handle Deep Links
Mapp plugin provides possibility to handle deep links received in push messages.
Deep-linking is a type of action that can be triggered when the user open the push notification. It provides the ability to open a specific page within the app.
Code Block |
---|
Mapp.addDeepLinkingListener(notification => { let action = notification.action; let url1 = notification.url; console.log(notification); const uri = new URL(url1); const link = url1; const message_id = action; //Alert.alert(JSON.stringify(url1)); this.props.navigation.navigate('Home', { myLink: link, message_id: message_id, }); }); |
Tags
Retrieving tags:
Code Block | ||
---|---|---|
| ||
Mapp.getTags().then(data => { Alert.alert(JSON.stringify(data)) }); |
Adding a tag:
@param{string
} tag - channel tag
Code Block | ||
---|---|---|
| ||
Mapp.addTag("tagName"); |
Removing tag:
@param{string
} tag - channel tag
Code Block | ||
---|---|---|
| ||
Mapp.removeTag("tagName"); |
...
Set a string value for a key.
@param {string} key - A key to be paired with the value.
@param {string} value - A value which contains string.
Code Block | ||
---|---|---|
| ||
Mapp.setAttributeString("some key", "some value"); |
...
Set a number value for a key.
@param {string} key - A key to be paired with the value.
@param {number} value - A value which contains a number, i.e. "34", "34.54".
Code Block | ||
---|---|---|
| ||
Mapp.setAttributeInt("some key", 34); |
...
Set a boolean for a key.
@param {string} key - A key to be paired with the value.
@param {boolean} value - true, false
Code Block | ||
---|---|---|
| ||
Mapp.setAttributeBollean("some key", true); |
...
To get inbox messages use Mapp.fetchInboxMessage()
Code Block | ||
---|---|---|
| ||
Mapp.fetchInboxMessage().then(data => { if (Platform.OS == "ios") { Mapp.addInboxMessagesListener( (messages) => { Alert.alert(JSON.stringify(messages)) }); } else { Alert.alert(JSON.stringify(data)) } |
iOS uses events for inbox messages (Mapp.addInboxMessagesListener
)and cannot return them as promise.
To get the latest inbox message use Mapp.fetchInboxMessage();
Code Block | ||
---|---|---|
| ||
const latestMessage = await Mapp.fetchLatestInboxMessage();
if (latestMessage != null) {
// use latest message
} |
Show In-App message
The method triggers an In-App message.
@param {string} event-specific DCM event trigger.
Code Block | ||
---|---|---|
| ||
Mapp.triggerInApp("app_open") |
...
@param{string} eventId
Code Block | ||
---|---|---|
| ||
Mapp.inAppMarkAsRead(templateId: number, eventId: string); Mapp.inAppMarkAsUnRead(templateId: number, eventId: string); Mapp.inAppMarkAsDeleted(templateId: number, eventId: string); |
...
Start location monitoring
To start Geofencing (Geo targeting) use command Mapp.startGeofencing()
The location manager will be enabled and it will collect the location change events.
Code Block | ||
---|---|---|
| ||
Mapp.startGeofencing() .then(result => { console.log(result); Alert.alert('Geofencing start', result); }) .catch((code, error) => { console.log(code, error); }); |
Info |
---|
On Android, application must request Location permissions in runtime, to be able to start Geofencing. |
Mapp
...
Stop location monitoring
plugin provides helper method to request required location permissions: COARSE_LOCATION, FINE_LOCATION, BACKGROUND_LOCATION.
Code Block | ||
---|---|---|
| ||
let result = await Mapp.requestGeofenceLocationPermission();
if(resul){
// location permissions are granted; Start Geofencing;
}else{
// permissions are denied; Handle permissions denial
} |
Note that requesting BACKGROUND_LOCATION has strict Google Policy and application must provide valid reasons to do that, otherwise Google can remove application from Google Play. More on this on official Google support pages.
Stop location monitoring
To stop Geofencing use command Mapp.stopGeoFencing()
The location manager will be disabled.
Code Block | ||
---|---|---|
| ||
Mapp.stopGeoFencing().stopGeofencing() .then(result => { console.log(result); Alert.alert('Geofencing stop', result); }) .catch((code, error) => { console.log(code, error); }); |