-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (73 loc) · 2.79 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
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
77
78
79
80
81
/**
* @format
*/
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import {SetDeviceToken} from './src/utils/controlToken';
import messaging from '@react-native-firebase/messaging';
import PushNotification, {Importance} from 'react-native-push-notification';
import * as RootNavigation from './src/navigation/RootNavigation';
PushNotification.createChannel(
{
channelId: 'fcm_fallback_notification_channel', // (required)
channelName: 'My channel', // (required)
channelDescription: 'A channel to categorise your notifications', // (optional) default: undefined.
playSound: true, // (optional) default: true
soundName: 'default', // (optional) See `soundName` parameter of `localNotification` function
importance: Importance.HIGH, // (optional) default: Importance.HIGH. Int value of the Android notification importance
vibrate: true, // (optional) default: true. Creates the default vibration pattern if true.
},
(created) => console.log(`createChannel returned '${created}'`), // (optional) callback returns whether the channel was created, false means it already existed.
);
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: async function (token) {
console.log('TOKEN:', token.token);
// AsyncStorage.setItem();
// AsyncStorage.setItem('deviceToken', token.token);
// await AsyncStorage.setItem('deviceToken', token.token, () => {
// console.log('deviceToken은 ' + token.token + '입니다');
// });
SetDeviceToken(token.token);
},
// (required) Called when a remote or local notification is opened or received
onNotification: function (notification) {
console.log('REMOTE NOTIFICATION ==>', notification);
if (!notification.userInteraction) {
LocalNotification(notification);
}
if (notification.userInteraction) {
RootNavigation.navigate('알림', '');
}
},
// Android only: GCM or FCM Sender ID
permissions: {
alert: true,
badge: true,
sound: true,
},
senderID: '334463887636',
popInitialNotification: true,
requestPermissions: true,
});
export const LocalNotification = (notification) => {
PushNotification.localNotification({
channelId: `${notification.channelId}`,
autoCancel: true,
bigText: `${notification.data.body}`,
title: `${notification.data.title}`,
userInteraction: false,
message: '더 보려면 아래로 늘리세요',
vibrate: true,
vibration: 300,
playSound: true,
soundName: 'default',
importance: 'high',
onlyAlertOnce: true,
});
};
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
console.log('Message handled in the background!', remoteMessage);
});
AppRegistry.registerComponent(appName, () => App);