2018-07-10 13:40:32 +00:00
|
|
|
import { NotificationsAndroid, PendingNotifications } from 'react-native-notifications';
|
|
|
|
|
|
|
|
class PushNotification {
|
|
|
|
constructor() {
|
|
|
|
this.onRegister = null;
|
|
|
|
this.onNotification = null;
|
|
|
|
this.deviceToken = null;
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
NotificationsAndroid.setRegistrationTokenUpdateListener(deviceToken => {
|
2018-07-10 13:40:32 +00:00
|
|
|
this.deviceToken = deviceToken;
|
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
NotificationsAndroid.setNotificationOpenedListener(notification => {
|
2018-07-10 13:40:32 +00:00
|
|
|
this.onNotification(notification);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getDeviceToken() {
|
|
|
|
return this.deviceToken;
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
setBadgeCount = () => {};
|
2018-10-31 18:40:39 +00:00
|
|
|
|
2018-07-10 13:40:32 +00:00
|
|
|
configure(params) {
|
|
|
|
this.onRegister = params.onRegister;
|
|
|
|
this.onNotification = params.onNotification;
|
2019-03-12 16:23:06 +00:00
|
|
|
NotificationsAndroid.refreshToken();
|
2019-03-18 18:52:38 +00:00
|
|
|
return PendingNotifications.getInitialNotification();
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new PushNotification();
|