Commit 5b58a301 authored by Libin Lu's avatar Libin Lu

update example

parent 6973949f
...@@ -48,7 +48,7 @@ class MainPage extends Component { ...@@ -48,7 +48,7 @@ class MainPage extends Component {
// Get information about the notification that was opened // Get information about the notification that was opened
const notif: Notification = notificationOpen.notification; const notif: Notification = notificationOpen.notification;
this.setState({ this.setState({
initNotif: notif initNotif: notif.data
}) })
if(notif && notif.targetScreen === 'detail'){ if(notif && notif.targetScreen === 'detail'){
setTimeout(()=>{ setTimeout(()=>{
...@@ -75,15 +75,13 @@ class MainPage extends Component { ...@@ -75,15 +75,13 @@ class MainPage extends Component {
firebase.messaging().subscribeToTopic('sometopic'); firebase.messaging().subscribeToTopic('sometopic');
firebase.messaging().unsubscribeFromTopic('sometopic'); firebase.messaging().unsubscribeFromTopic('sometopic');
AsyncStorage.getItem('lastNotification').then(data=>{ var offline = await AsyncStorage.getItem('headless')
if(data){ if(offline){
// if notification arrives when app is killed, it should still be logged here
this.setState({ this.setState({
offlineNotif: JSON.parse(data) offlineNotif: offline
}); });
AsyncStorage.removeItem('lastNotification'); AsyncStorage.removeItem('headless');
} }
})
} }
componentWillUnmount(){ componentWillUnmount(){
...@@ -208,7 +206,7 @@ class MainPage extends Component { ...@@ -208,7 +206,7 @@ class MainPage extends Component {
Notif when app was closed: Notif when app was closed:
</Text> </Text>
<Text> <Text>
{JSON.stringify(this.state.offlineNotif)} {this.state.offlineNotif}
</Text> </Text>
<Text style={styles.instructions}> <Text style={styles.instructions}>
......
...@@ -16,8 +16,8 @@ function displayNotificationFromCustomData(message: RemoteMessage){ ...@@ -16,8 +16,8 @@ function displayNotificationFromCustomData(message: RemoteMessage){
} }
} }
export async function registerKilledListener(message: RemoteMessage){ export async function registerHeadlessListener(message: RemoteMessage){
await AsyncStorage.setItem('lastNotification', JSON.stringify(message.data)); await AsyncStorage.setItem('headless', new Date().toISOString());
displayNotificationFromCustomData(message); displayNotificationFromCustomData(message);
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
*/ */
import React, { Component } from 'react'; import React, { Component } from 'react';
import {registerKilledListener} from './app/Listeners'; import {registerHeadlessListener} from './app/Listeners';
import { import {
AppRegistry, AppRegistry,
...@@ -24,4 +24,4 @@ export default class SimpleFcmClient extends Component { ...@@ -24,4 +24,4 @@ export default class SimpleFcmClient extends Component {
AppRegistry.registerComponent('SimpleFcmClient', () => SimpleFcmClient); AppRegistry.registerComponent('SimpleFcmClient', () => SimpleFcmClient);
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => registerKilledListener); AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => registerHeadlessListener);
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