-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
76 lines (68 loc) · 1.87 KB
/
index.js
File metadata and controls
76 lines (68 loc) · 1.87 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* @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 notifee, {AndroidImportance} from '@notifee/react-native';
// message object
// {
// "data": {
// "body": "hlow",
// "title": "user1"
// },
// "from": "141554066415",
// "messageId": "0:1728406665031374%50962712f9fd7ecd",
// "sentTime": 1728406665023,
// "ttl": 2419200
// }
async function onBackgroundMessasgeReceived(message) {
const channelId = await notifee.createChannel({
id: 'background_notification_channel',
name: 'Message notifications',
importance: AndroidImportance.HIGH,
sound: 'message',
});
await notifee.displayNotification({
id: message.messageId,
title: message.data.title,
body: message.data.body,
data: message.data,
android: {
channelId,
smallIcon: 'ic_launcher_foreground',
// largeIcon: ImageAssets.Logo,
importance: AndroidImportance.HIGH,
sound: 'message',
pressAction: {
id: 'default',
},
},
});
}
async function onForegroundMessageReceived(message) {
const channelId = await notifee.createChannel({
id: 'foreground_notification_channel',
name: 'Silent notifications',
importance: AndroidImportance.LOW,
});
await notifee.displayNotification({
id: message.messageId,
title: message.data.title,
body: message.data.body,
data: message.data,
android: {
channelId,
smallIcon: 'ic_launcher_foreground',
// largeIcon: ImageAssets.Logo,
importance: AndroidImportance.LOW,
pressAction: {
id: 'default',
},
},
});
}
messaging().onMessage(onForegroundMessageReceived);
messaging().setBackgroundMessageHandler(onBackgroundMessasgeReceived);
AppRegistry.registerComponent(appName, () => App);