From 5b58a301ee8e3a9b0373cd11ea3bc25795c562e0 Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Thu, 26 Apr 2018 13:57:52 -0400 Subject: [PATCH] update example --- Examples/firebase-migration/app/App.js | 20 +++++++++----------- Examples/firebase-migration/app/Listeners.js | 4 ++-- Examples/firebase-migration/index.android.js | 4 ++-- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Examples/firebase-migration/app/App.js b/Examples/firebase-migration/app/App.js index 9e17592..7358999 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 f66b938..9685c2d 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 32594e5..64d1b62 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); -- 2.26.2