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

update example

parent 6973949f
......@@ -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:
</Text>
<Text>
{JSON.stringify(this.state.offlineNotif)}
{this.state.offlineNotif}
</Text>
<Text style={styles.instructions}>
......
......@@ -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);
}
......
......@@ -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);
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