vn-verdnaturachat/app/notifications/push/push.ios.js

39 lines
952 B
JavaScript
Raw Normal View History

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, completion) => {
this.onNotification(notification);
completion();
});
NotificationsIOS.requestPermissions();
}
getDeviceToken() {
return this.deviceToken;
}
setBadgeCount = (count = 0) => {
NotificationsIOS.setBadgesCount(count);
}
async configure(params) {
this.onRegister = params.onRegister;
this.onNotification = params.onNotification;
const initial = await NotificationsIOS.getInitialNotification();
// NotificationsIOS.consumeBackgroundQueue();
return Promise.resolve(initial);
}
}
export default new PushNotification();