-
Notifications
You must be signed in to change notification settings - Fork 4
/
NotificationService.js
62 lines (52 loc) · 1.48 KB
/
NotificationService.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
import PushNotification from 'react-native-push-notification';
export default class NotificationService {
//onNotificaitn is a function passed in that is to be called when a
//notification is to be emitted.
constructor(onNotification) {
this.configure(onNotification);
this.lastId = 0;
}
configure(onNotification) {
PushNotification.configure({
onNotification: onNotification,
// IOS ONLY (optional): default: all - Permissions to register.
permissions: {
alert: true,
badge: true,
sound: true
},
popInitialNotification: true,
});
}
//Appears right away
localNotification() {
this.lastId++;
PushNotification.localNotification({
title: "Local Notification",
message: "My Notification Message",
playSound: false,
soundName: 'default',
actions: '["Yes", "No"]'
});
}
//Appears after a specified time. App does not have to be open.
scheduleNotification() {
this.lastId++;
PushNotification.localNotificationSchedule({
date: new Date(Date.now() + (30 * 1000)), //30 seconds
title: "Scheduled Notification",
message: "My Notification Message",
playSound: true,
soundName: 'default',
});
}
checkPermission(cbk) {
return PushNotification.checkPermissions(cbk);
}
cancelNotif() {
PushNotification.cancelLocalNotifications({id: ''+this.lastId});
}
cancelAll() {
PushNotification.cancelAllLocalNotifications();
}
}