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);
|
|
|
|
}
|
|
|
|
|
2019-06-26 12:33:56 +00:00
|
|
|
async configure(params) {
|
2018-07-10 13:40:32 +00:00
|
|
|
this.onRegister = params.onRegister;
|
|
|
|
this.onNotification = params.onNotification;
|
|
|
|
|
2019-06-26 12:33:56 +00:00
|
|
|
const initial = await NotificationsIOS.getInitialNotification();
|
2018-07-10 13:40:32 +00:00
|
|
|
NotificationsIOS.consumeBackgroundQueue();
|
2019-06-26 12:33:56 +00:00
|
|
|
return Promise.resolve(initial);
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export default new PushNotification();
|