-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (35 loc) · 1.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* @format
*/
import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
import messaging from '@react-native-firebase/messaging';
import PushNotification from 'react-native-push-notification';
// Foreground notification handler
messaging().onMessage(async remoteMessage => {
console.log('Foreground message received:', JSON.stringify(remoteMessage));
const { notification } = remoteMessage;
if (notification) {
const { title, body } = notification;
PushNotification.localNotification({
channelId: 'default-channel-id', // Ensure the channelId matches the one created in App.js
title: title || 'Notification Title',
message: body || 'Notification Body',
});
}
});
// Background notification handler
messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log('Background message received:', JSON.stringify(remoteMessage));
const { notification } = remoteMessage;
if (notification) {
const { title, body } = notification;
PushNotification.localNotification({
channelId: 'default-channel-id',
title: title || 'Notification Title',
message: body || 'Notification Body',
});
}
});
AppRegistry.registerComponent(appName, () => App);