Commit fbe27081 authored by Libin Lu's avatar Libin Lu

show last notification

parent e340c109
...@@ -73,6 +73,16 @@ class MainPage extends Component { ...@@ -73,6 +73,16 @@ class MainPage extends Component {
// topic example // topic example
firebase.messaging().subscribeToTopic('sometopic'); firebase.messaging().subscribeToTopic('sometopic');
firebase.messaging().unsubscribeFromTopic('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(){ componentWillUnmount(){
...@@ -192,7 +202,14 @@ class MainPage extends Component { ...@@ -192,7 +202,14 @@ class MainPage extends Component {
Init notif: Init notif:
</Text> </Text>
<Text> <Text>
{JSON.stringify(this.state.initNotif && this.state.initNotif.data)} {JSON.stringify(this.state.initNotif)}
</Text>
<Text style={styles.instructions}>
Notif when app was closed:
</Text>
<Text>
{JSON.stringify(this.state.offlineNotif)}
</Text> </Text>
<Text style={styles.instructions}> <Text style={styles.instructions}>
......
...@@ -2,14 +2,6 @@ import { Platform, AsyncStorage, AppState } from 'react-native'; ...@@ -2,14 +2,6 @@ import { Platform, AsyncStorage, AppState } from 'react-native';
import firebase from 'react-native-firebase'; 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){ function displayNotificationFromCustomData(message: RemoteMessage){
if(message.data && message.data.custom_notification){ if(message.data && message.data.custom_notification){
let notification = new firebase.notifications.Notification(); let notification = new firebase.notifications.Notification();
...@@ -24,7 +16,7 @@ function displayNotificationFromCustomData(message: RemoteMessage){ ...@@ -24,7 +16,7 @@ function displayNotificationFromCustomData(message: RemoteMessage){
} }
export function registerKilledListener(message: RemoteMessage){ export function registerKilledListener(message: RemoteMessage){
AsyncStorage.setItem('lastNotification', JSON.stringify(message)); AsyncStorage.setItem('lastNotification', JSON.stringify(message.data));
displayNotificationFromCustomData(); displayNotificationFromCustomData();
} }
......
...@@ -54,7 +54,6 @@ ...@@ -54,7 +54,6 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"> shouldUseLaunchSchemeArgsEnv = "YES">
<Testables> <Testables>
<TestableReference <TestableReference
...@@ -84,7 +83,6 @@ ...@@ -84,7 +83,6 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment