2017-11-28 00:50:46 +02:00
|
|
|
const PushNotification = require('react-native-push-notification');
|
|
|
|
|
|
|
|
class AlarmServiceDriver {
|
|
|
|
|
2017-11-28 02:22:38 +02:00
|
|
|
hasPersistentNotifications() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
notificationIsSet(alarmId) {
|
|
|
|
throw new Error('Available only for non-persistent alarms');
|
|
|
|
}
|
|
|
|
|
2017-11-28 00:50:46 +02:00
|
|
|
async clearNotification(id) {
|
2017-11-28 21:49:03 +02:00
|
|
|
PushNotification.cancelLocalNotifications({ id: id + '' });
|
2017-11-28 00:50:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async scheduleNotification(notification) {
|
2017-11-28 21:49:03 +02:00
|
|
|
// Arguments must be set in a certain way and certain format otherwise it cannot be
|
|
|
|
// cancelled later on. See:
|
|
|
|
// https://github.com/zo0r/react-native-push-notification/issues/570#issuecomment-337642922
|
2017-11-28 00:50:46 +02:00
|
|
|
const androidNotification = {
|
2017-11-28 21:49:03 +02:00
|
|
|
id: notification.id + '',
|
|
|
|
message: notification.title,
|
2017-11-28 00:50:46 +02:00
|
|
|
date: notification.date,
|
2017-11-28 21:49:03 +02:00
|
|
|
userInfo: { id: notification.id + '' },
|
|
|
|
number: 0,
|
2017-11-28 00:50:46 +02:00
|
|
|
};
|
|
|
|
|
2017-11-28 20:58:04 +02:00
|
|
|
if ('body' in notification) androidNotification.body = notification.body;
|
2017-11-28 00:50:46 +02:00
|
|
|
|
|
|
|
PushNotification.localNotificationSchedule(androidNotification);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AlarmServiceDriver;
|