// when the app is running, but in the backgroud messaging().onNotificationOpenedApp(remoteMessage => { console.log( '[FCMService] onNotificationOpenedApp Notification caused app to open', ); if (remoteMessage) { const notification = remoteMessage.notification; onOpenNotification(notification); // this.removeDeliveredNotification(notification.notificationId) } });
// when the app is opened from a quit state. messaging() .getInitialNotification() .then(remoteMessage => { console.log( '[FCMService] getInitialNotification Notification caused app to open', ); if (remoteMessage) { const notification = remoteMessage.notification; onOpenNotification(notification); // this.removeDeliveredNotification(notification.notificationId) } });
messaging().onMessage(async remoteMessage => { console.log('[FCMService] a new FCM message arrived!', remoteMessage); if (remoteMessage) { let notification = null; if (Platform.OS === 'ios') { notification = remoteMessage.data.notification; } else { notification = remoteMessage.notification; } onNotification(notification); } })