-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (33 loc) · 1.04 KB
/
index.js
File metadata and controls
40 lines (33 loc) · 1.04 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
/**
* @format
*/
import {AppRegistry} from 'react-native';
import App from './src/App';
import messaging from '@react-native-firebase/messaging';
import {name as appName} from './app.json';
// 백그라운드 상태
messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log('Message handled in the background!', remoteMessage);
const { notification } = remoteMessage;
const fcmToken = await messaging().getToken();
const requestBody = {
fcmToken: fcmToken,
title: notification?.title || 'Default Title',
body: notification?.body || 'Default Body',
};
try {
const response = await fetch('http://211.188.51.4/feign/fcm', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody),
});
if (!response.ok) {
console.error('Failed to send FCM message to server:', response.statusText);
}
} catch (error) {
console.error('Error sending FCM message:', error);
}
});
AppRegistry.registerComponent(appName, () => App);