Commit 80b412d9 authored by Libin Lu's avatar Libin Lu

change

parent 9345da2b
...@@ -12,7 +12,8 @@ import { ...@@ -12,7 +12,8 @@ import {
View, View,
Clipboard, Clipboard,
Platform, Platform,
ScrollView ScrollView,
AsyncStorage
} from 'react-native'; } from 'react-native';
import { StackNavigator } from 'react-navigation'; import { StackNavigator } from 'react-navigation';
...@@ -140,14 +141,10 @@ class MainPage extends Component { ...@@ -140,14 +141,10 @@ class MainPage extends Component {
body = { body = {
"to": token, "to": token,
"data":{ "data":{
"custom_notification": { "title": "Simple FCM Client",
"title": "Simple FCM Client", "body": "Click me to go to detail",
"body": "Click me to go to detail", targetScreen: 'detail',
data: { now: new Date().toISOString()
targetScreen: 'detail',
now: new Date().toISOString()
}
}
}, },
"priority": 10 "priority": 10
} }
......
...@@ -3,13 +3,14 @@ import { Platform, AsyncStorage, AppState } from 'react-native'; ...@@ -3,13 +3,14 @@ import { Platform, AsyncStorage, AppState } from 'react-native';
import firebase from 'react-native-firebase'; import firebase from 'react-native-firebase';
function displayNotificationFromCustomData(message: RemoteMessage){ function displayNotificationFromCustomData(message: RemoteMessage){
if(message.data && message.data.custom_notification){ if(message.data && message.data.title){
let notification = new firebase.notifications.Notification(); let notification = new firebase.notifications.Notification();
notification = notification.setNotificationId(new Date().valueOf().toString()) notification = notification
.setTitle(message.title) .setTitle(message.data.title)
.setBody(message.body) .setBody(message.data.body)
.setData(message.data) .setData(message.data)
.setSound("bell.mp3") .setSound("bell.mp3")
notification.android.setPriority(firebase.notifications.Android.Priority.High)
notification.android.setChannelId("test-channel") notification.android.setChannelId("test-channel")
firebase.notifications().displayNotification(notification); firebase.notifications().displayNotification(notification);
} }
...@@ -17,7 +18,7 @@ function displayNotificationFromCustomData(message: RemoteMessage){ ...@@ -17,7 +18,7 @@ function displayNotificationFromCustomData(message: RemoteMessage){
export async function registerKilledListener(message: RemoteMessage){ export async function registerKilledListener(message: RemoteMessage){
await AsyncStorage.setItem('lastNotification', JSON.stringify(message.data)); await AsyncStorage.setItem('lastNotification', JSON.stringify(message.data));
displayNotificationFromCustomData(); displayNotificationFromCustomData(message);
} }
// these callback will be triggered only when app is foreground or background // these callback will be triggered only when app is foreground or background
...@@ -43,7 +44,7 @@ export function registerAppListener(navigation){ ...@@ -43,7 +44,7 @@ export function registerAppListener(navigation){
}); });
this.messageListener = firebase.messaging().onMessage((message: RemoteMessage) => { this.messageListener = firebase.messaging().onMessage((message: RemoteMessage) => {
displayNotificationFromCustomData(); displayNotificationFromCustomData(message);
}); });
} }
......
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