diff --git a/Examples/firebase-migration/app/App.js b/Examples/firebase-migration/app/App.js index 2dedfa1fc651db3ffb39c7856c22e31f6f16c8e6..83da15d39b49d9f8e1b3ca427600646afc602354 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 d03e2fb5c88ec85c030a4636727a8fcb9c754d81..f66b938092265d9eba1e12e435ca2b632a56c241 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); }); }