From fbe270815a3305132cff77b0467417cd0614ba63 Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Mon, 16 Apr 2018 00:07:54 -0400 Subject: [PATCH] show last notification --- Examples/firebase-migration/app/App.js | 19 ++++++++++++++++++- Examples/firebase-migration/app/Listeners.js | 10 +--------- .../xcschemes/SimpleFcmClient.xcscheme | 2 -- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Examples/firebase-migration/app/App.js b/Examples/firebase-migration/app/App.js index d831bca..74b70d5 100644 --- a/Examples/firebase-migration/app/App.js +++ b/Examples/firebase-migration/app/App.js @@ -73,6 +73,16 @@ class MainPage extends Component { // topic example 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'); + } + }) } componentWillUnmount(){ @@ -192,7 +202,14 @@ class MainPage extends Component { Init notif: - {JSON.stringify(this.state.initNotif && this.state.initNotif.data)} + {JSON.stringify(this.state.initNotif)} + + + + Notif when app was closed: + + + {JSON.stringify(this.state.offlineNotif)} diff --git a/Examples/firebase-migration/app/Listeners.js b/Examples/firebase-migration/app/Listeners.js index eba5805..c13f8f3 100644 --- a/Examples/firebase-migration/app/Listeners.js +++ b/Examples/firebase-migration/app/Listeners.js @@ -2,14 +2,6 @@ import { Platform, AsyncStorage, AppState } from 'react-native'; import firebase from 'react-native-firebase'; -AsyncStorage.getItem('lastNotification').then(data=>{ - if(data){ - // if notification arrives when app is killed, it should still be logged here - console.log('last notification', JSON.parse(data)); - AsyncStorage.removeItem('lastNotification'); - } -}) - function displayNotificationFromCustomData(message: RemoteMessage){ if(message.data && message.data.custom_notification){ let notification = new firebase.notifications.Notification(); @@ -24,7 +16,7 @@ function displayNotificationFromCustomData(message: RemoteMessage){ } export function registerKilledListener(message: RemoteMessage){ - AsyncStorage.setItem('lastNotification', JSON.stringify(message)); + AsyncStorage.setItem('lastNotification', JSON.stringify(message.data)); displayNotificationFromCustomData(); } diff --git a/Examples/firebase-migration/ios/SimpleFcmClient.xcodeproj/xcshareddata/xcschemes/SimpleFcmClient.xcscheme b/Examples/firebase-migration/ios/SimpleFcmClient.xcodeproj/xcshareddata/xcschemes/SimpleFcmClient.xcscheme index 8432ca9..5f74c52 100644 --- a/Examples/firebase-migration/ios/SimpleFcmClient.xcodeproj/xcshareddata/xcschemes/SimpleFcmClient.xcscheme +++ b/Examples/firebase-migration/ios/SimpleFcmClient.xcodeproj/xcshareddata/xcschemes/SimpleFcmClient.xcscheme @@ -54,7 +54,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" shouldUseLaunchSchemeArgsEnv = "YES">