-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotifService.js
73 lines (58 loc) · 1.91 KB
/
NotifService.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
import PushNotification from 'react-native-push-notification'
export default class NotifService {
constructor(onRegister, onNotification) {
this.configure(onRegister, onNotification)
this.lastId = 0
}
configure(onRegister, onNotification, gcm = '') {
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: onRegister, //this._onRegister.bind(this),
// (required) Called when a remote or local notification is opened or received
onNotification: onNotification, //this._onNotification,
// ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
senderID: gcm,
// IOS ONLY (optional): default: all - Permissions to register.
permissions: {
alert: true,
badge: true,
sound: true
},
// Should the initial notification be popped automatically
// default: true
popInitialNotification: true,
/*
* (optional) default: true
* - Specified if permissions (ios) and token (android and ios) will requested or not,
* - if not, you must call PushNotificationsHandler.requestPermissions() later
*/
requestPermissions: true
})
}
notificationContent = {
largeIcon: 'ic_launcher',
/* iOS and Android properties */
title: 'Remote Work',
message: 'Found new jobs for you!'
}
localNotif() {
this.lastId++,
PushNotification.localNotification(this.notificationContent)
}
scheduleNotif(date) {
this.lastId++
PushNotification.localNotificationSchedule({
date,
notificationContent
})
}
checkPermission(cbk) {
return PushNotification.checkPermissions(cbk)
}
cancelNotif() {
PushNotification.cancelLocalNotifications({id: '' + this.lastId})
}
cancelAll() {
PushNotification.cancelAllLocalNotifications()
}
}