2018-07-10 13:40:32 +00:00
|
|
|
import NotificationsIOS from 'react-native-notifications';
|
|
|
|
|
|
|
|
class PushNotification {
|
|
|
|
constructor() {
|
|
|
|
this.onRegister = null;
|
|
|
|
this.onNotification = null;
|
|
|
|
this.deviceToken = null;
|
|
|
|
|
|
|
|
NotificationsIOS.addEventListener('remoteNotificationsRegistered', (deviceToken) => {
|
|
|
|
this.deviceToken = deviceToken;
|
|
|
|
});
|
|
|
|
|
|
|
|
NotificationsIOS.addEventListener('notificationOpened', (notification) => {
|
|
|
|
this.onNotification(notification);
|
|
|
|
});
|
|
|
|
|
|
|
|
NotificationsIOS.requestPermissions();
|
|
|
|
}
|
|
|
|
|
|
|
|
getDeviceToken() {
|
|
|
|
return this.deviceToken;
|
|
|
|
}
|
|
|
|
|
2018-10-31 18:40:39 +00:00
|
|
|
setBadgeCount = (count = 0) => {
|
|
|
|
NotificationsIOS.setBadgesCount(count);
|
|
|
|
}
|
|
|
|
|
2018-07-10 13:40:32 +00:00
|
|
|
configure(params) {
|
|
|
|
this.onRegister = params.onRegister;
|
|
|
|
this.onNotification = params.onNotification;
|
|
|
|
|
|
|
|
NotificationsIOS.consumeBackgroundQueue();
|
2019-03-18 18:52:38 +00:00
|
|
|
return Promise.resolve();
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export default new PushNotification();
|