Get Initial Notification
When your app is instantiated by clicking on push notification, you may need its payload;
In order to get it, use getInitialNotification
function
import React, { useEffect } from 'react';
import { Alert } from 'react-native';
import { getInitialNotification } from 'reteno-react-native-sdk';
useEffect(() => {
getInitialNotification().then((data) => {
Alert.alert('getInitialNotification', data ? JSON.stringify(data) : data);
});
}, []);
Listen for New Push Notifications While App is Active
While app is open, you may need to track, if there is new push;
To do so, set listener using setOnRetenoPushReceivedListener
function;
import React, { useCallback, useEffect } from 'react';
import { Alert } from 'react-native';
import { setOnRetenoPushReceivedListener } from 'reteno-react-native-sdk';
const onRetenoPushReceived = useCallback((event) => {
Alert.alert('onRetenoPushReceived', event ? JSON.stringify(event) : event);
}, []);
useEffect(() => {
const pushListener = setOnRetenoPushReceivedListener(onRetenoPushReceived);
return () => pushListener.remove();
}, [onRetenoPushReceived]);