From 80b412d9e29b3048fd43d848b10d703a739a2113 Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Mon, 23 Apr 2018 14:42:17 -0400 Subject: [PATCH] change --- Examples/firebase-migration/app/App.js | 15 ++++++--------- Examples/firebase-migration/app/Listeners.js | 13 +++++++------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Examples/firebase-migration/app/App.js b/Examples/firebase-migration/app/App.js index 2dedfa1..83da15d 100644 --- a/Examples/firebase-migration/app/App.js +++ b/Examples/firebase-migration/app/App.js @@ -12,7 +12,8 @@ import { View, Clipboard, Platform, - ScrollView + ScrollView, + AsyncStorage } from 'react-native'; import { StackNavigator } from 'react-navigation'; @@ -140,14 +141,10 @@ class MainPage extends Component { body = { "to": token, "data":{ - "custom_notification": { - "title": "Simple FCM Client", - "body": "Click me to go to detail", - data: { - targetScreen: 'detail', - now: new Date().toISOString() - } - } + "title": "Simple FCM Client", + "body": "Click me to go to detail", + targetScreen: 'detail', + now: new Date().toISOString() }, "priority": 10 } diff --git a/Examples/firebase-migration/app/Listeners.js b/Examples/firebase-migration/app/Listeners.js index d03e2fb..f66b938 100644 --- a/Examples/firebase-migration/app/Listeners.js +++ b/Examples/firebase-migration/app/Listeners.js @@ -3,13 +3,14 @@ import { Platform, AsyncStorage, AppState } from 'react-native'; import firebase from 'react-native-firebase'; function displayNotificationFromCustomData(message: RemoteMessage){ - if(message.data && message.data.custom_notification){ + if(message.data && message.data.title){ let notification = new firebase.notifications.Notification(); - notification = notification.setNotificationId(new Date().valueOf().toString()) - .setTitle(message.title) - .setBody(message.body) + notification = notification + .setTitle(message.data.title) + .setBody(message.data.body) .setData(message.data) .setSound("bell.mp3") + notification.android.setPriority(firebase.notifications.Android.Priority.High) notification.android.setChannelId("test-channel") firebase.notifications().displayNotification(notification); } @@ -17,7 +18,7 @@ function displayNotificationFromCustomData(message: RemoteMessage){ export async function registerKilledListener(message: RemoteMessage){ await AsyncStorage.setItem('lastNotification', JSON.stringify(message.data)); - displayNotificationFromCustomData(); + displayNotificationFromCustomData(message); } // these callback will be triggered only when app is foreground or background @@ -43,7 +44,7 @@ export function registerAppListener(navigation){ }); this.messageListener = firebase.messaging().onMessage((message: RemoteMessage) => { - displayNotificationFromCustomData(); + displayNotificationFromCustomData(message); }); } -- 2.26.2