2019-01-10 20:49:26 +02:00
|
|
|
const PushNotification = require('react-native-push-notification');
|
2017-11-28 00:50:46 +02:00
|
|
|
|
|
|
|
class AlarmServiceDriver {
|
2019-01-10 20:49:26 +02:00
|
|
|
PushNotificationHandler_() {
|
|
|
|
if (!this.PushNotification_) {
|
|
|
|
PushNotification.configure({
|
2019-07-29 15:43:53 +02:00
|
|
|
// (required) Called when a remote or local notification is opened or received
|
|
|
|
onNotification: function(notification) {
|
|
|
|
console.info('Notification was opened: ', notification);
|
|
|
|
// process the notification
|
|
|
|
},
|
|
|
|
popInitialNotification: true,
|
|
|
|
requestPermissions: true,
|
2019-01-10 20:49:26 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.PushNotification_ = PushNotification;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.PushNotification_;
|
2018-12-20 15:52:56 +02:00
|
|
|
}
|
|
|
|
|
2017-11-28 02:22:38 +02:00
|
|
|
hasPersistentNotifications() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-13 00:16:42 +02:00
|
|
|
notificationIsSet() {
|
2019-07-29 15:43:53 +02:00
|
|
|
throw new Error('Available only for non-persistent alarms');
|
2017-11-28 02:22:38 +02:00
|
|
|
}
|
|
|
|
|
2017-11-28 00:50:46 +02:00
|
|
|
async clearNotification(id) {
|
2019-09-19 23:51:18 +02:00
|
|
|
return this.PushNotificationHandler_().cancelLocalNotifications({ id: `${id}` });
|
2017-11-28 00:50:46 +02:00
|
|
|
}
|
2019-07-29 15:43:53 +02:00
|
|
|
|
2017-11-28 00:50:46 +02:00
|
|
|
async scheduleNotification(notification) {
|
2019-01-10 20:49:26 +02:00
|
|
|
const config = {
|
2019-09-19 23:51:18 +02:00
|
|
|
id: `${notification.id}`,
|
2019-01-10 20:49:26 +02:00
|
|
|
message: notification.title,
|
|
|
|
date: notification.date,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.PushNotificationHandler_().localNotificationSchedule(config);
|
2017-11-28 00:50:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
module.exports = AlarmServiceDriver;
|