diff --git a/Examples/firebase-migration/app/App.js b/Examples/firebase-migration/app/App.js index 9e17592787190cad050f692fa28de457c1a1c18b..73589998a7a517003c83efbc02a7961e8b391102 100644 --- a/Examples/firebase-migration/app/App.js +++ b/Examples/firebase-migration/app/App.js @@ -48,7 +48,7 @@ class MainPage extends Component { // Get information about the notification that was opened const notif: Notification = notificationOpen.notification; this.setState({ - initNotif: notif + initNotif: notif.data }) if(notif && notif.targetScreen === 'detail'){ setTimeout(()=>{ @@ -75,15 +75,13 @@ class MainPage extends Component { firebase.messaging().subscribeToTopic('sometopic'); firebase.messaging().unsubscribeFromTopic('sometopic'); - AsyncStorage.getItem('lastNotification').then(data=>{ - if(data){ - // if notification arrives when app is killed, it should still be logged here - this.setState({ - offlineNotif: JSON.parse(data) - }); - AsyncStorage.removeItem('lastNotification'); - } - }) + var offline = await AsyncStorage.getItem('headless') + if(offline){ + this.setState({ + offlineNotif: offline + }); + AsyncStorage.removeItem('headless'); + } } componentWillUnmount(){ @@ -208,7 +206,7 @@ class MainPage extends Component { Notif when app was closed: - {JSON.stringify(this.state.offlineNotif)} + {this.state.offlineNotif} diff --git a/Examples/firebase-migration/app/Listeners.js b/Examples/firebase-migration/app/Listeners.js index f66b938092265d9eba1e12e435ca2b632a56c241..9685c2d2d1288e4909a78484937c0f48d1e3995f 100644 --- a/Examples/firebase-migration/app/Listeners.js +++ b/Examples/firebase-migration/app/Listeners.js @@ -16,8 +16,8 @@ function displayNotificationFromCustomData(message: RemoteMessage){ } } -export async function registerKilledListener(message: RemoteMessage){ - await AsyncStorage.setItem('lastNotification', JSON.stringify(message.data)); +export async function registerHeadlessListener(message: RemoteMessage){ + await AsyncStorage.setItem('headless', new Date().toISOString()); displayNotificationFromCustomData(message); } diff --git a/Examples/firebase-migration/index.android.js b/Examples/firebase-migration/index.android.js index 32594e59834a8984a65e01c87caed6df3bb06df6..64d1b62041da77d6ed06dffcfde9fcbc76dcbd52 100644 --- a/Examples/firebase-migration/index.android.js +++ b/Examples/firebase-migration/index.android.js @@ -5,7 +5,7 @@ */ import React, { Component } from 'react'; -import {registerKilledListener} from './app/Listeners'; +import {registerHeadlessListener} from './app/Listeners'; import { AppRegistry, @@ -24,4 +24,4 @@ export default class SimpleFcmClient extends Component { AppRegistry.registerComponent('SimpleFcmClient', () => SimpleFcmClient); -AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => registerKilledListener); +AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => registerHeadlessListener);