-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathNotifications.js
48 lines (44 loc) · 1.36 KB
/
Notifications.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
import PushNotification from 'react-native-push-notification';
import PushNotificationIOS from '@react-native-community/push-notification-ios';
class Notifications {
constructor() {
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: function (token) {
// console.log('TOKEN:', token);
},
onNotification: function (notification) {
console.log('NOTIFICATION:', notification);
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
popInitialNotification: true,
requestPermissions: true,
// IOS ONLY (optional): default: all - Permissions to register.
permissions: {
alert: true,
badge: false,
sound: false,
},
});
PushNotification.createChannel(
{
channelId: 'reminders', // (required)
channelName: 'Task reminder notifications', // (required)
channelDescription: 'Reminder for any tasks',
},
() => {},
);
PushNotification.getScheduledLocalNotifications(rn => {
console.log('SN --- ', rn);
});
}
schduleNotification(date) {
PushNotification.localNotificationSchedule({
channelId: 'reminders',
title: '🔔 Reminder!',
message: 'You have set this reminder',
date,
});
}
}
export default new Notifications();