Skip to content

Instantly share code, notes, and snippets.

@Karthik-B-06
Created January 12, 2021 13:04
Show Gist options
  • Save Karthik-B-06/af0c5360727024186ad175e7eb165539 to your computer and use it in GitHub Desktop.
Save Karthik-B-06/af0c5360727024186ad175e7eb165539 to your computer and use it in GitHub Desktop.
useEffect(() => {
// When notification is received in foreground
messaging().onMessage((remoteMessage) => {
Alert.alert('A new FCM message arrived!', JSON.stringify(remoteMessage));
});
// When an app is opened through notification
messaging().onNotificationOpenedApp((remoteMessage) => {
console.log('Notification caused app to open from background state:', remoteMessage.notification);
});
// Check whether an initial notification is available
messaging()
.getInitialNotification()
.then((remoteMessage) => {
if (remoteMessage) {
console.log('Notification caused app to open from quit state:', remoteMessage.notification);
}
})
.finally(() => null);
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment