-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (38 loc) · 1.16 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
43
44
45
46
47
48
49
/**
* @format
*/
import { AppRegistry } from 'react-native'
import App from './App'
import { name as appName } from './app.json'
import TrackPlayer from 'react-native-track-player'
import messaging from '@react-native-firebase/messaging'
import { PlaybackService } from '@services/PlaybackService'
import Notifee, { AndroidImportance } from '@notifee/react-native'
const setupNotificationChannel = async () => {
const channelId = await Notifee.createChannel({
id: 'default',
name: 'releases',
vibration: true,
importance: AndroidImportance.HIGH,
})
return channelId
}
async function onMessageReceived(remoteMessage) {
const title = remoteMessage.notification.title
const body = remoteMessage.notification.body
const channelId = await setupNotificationChannel()
await Notifee.displayNotification({
title,
body,
android: {
channelId,
smallIcon: '@mipmap/icon',
},
})
}
messaging().onMessage(onMessageReceived)
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
return remoteMessage
})
AppRegistry.registerComponent(appName, () => App)
TrackPlayer.registerPlaybackService(() => PlaybackService)