From e340c1091c51ea38b916f6f9738bae5c0616e7e3 Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Sun, 15 Apr 2018 23:54:04 -0400 Subject: [PATCH] handle headless --- Examples/firebase-migration/app/Listeners.js | 25 ++++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Examples/firebase-migration/app/Listeners.js b/Examples/firebase-migration/app/Listeners.js index 8751894..eba5805 100644 --- a/Examples/firebase-migration/app/Listeners.js +++ b/Examples/firebase-migration/app/Listeners.js @@ -10,8 +10,22 @@ AsyncStorage.getItem('lastNotification').then(data=>{ } }) +function displayNotificationFromCustomData(message: RemoteMessage){ + if(message.data && message.data.custom_notification){ + let notification = new firebase.notifications.Notification(); + notification = notification.setNotificationId(new Date().valueOf().toString()) + .setTitle(message.title) + .setBody(message.body) + .setData(message.data) + .setSound("bell.mp3") + notification.android.setChannelId("test-channel") + firebase.notifications().displayNotification(notification); + } +} + export function registerKilledListener(message: RemoteMessage){ AsyncStorage.setItem('lastNotification', JSON.stringify(message)); + displayNotificationFromCustomData(); } // these callback will be triggered only when app is foreground or background @@ -37,16 +51,7 @@ export function registerAppListener(navigation){ }); this.messageListener = firebase.messaging().onMessage((message: RemoteMessage) => { - if(message.data && message.data.custom_notification){ - let notification = new firebase.notifications.Notification(); - notification = notification.setNotificationId(new Date().valueOf().toString()) - .setTitle(message.title) - .setBody(message.body) - .setData(message.data) - .setSound("bell.mp3") - notification.android.setChannelId("test-channel") - firebase.notifications().displayNotification(notification); - } + displayNotificationFromCustomData(); }); } -- 2.26.2