Created
March 30, 2018 16:06
-
-
Save Sampath-Lokuge/132e7d2b9f6b9d9c89967d9fcfe892a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//schedule Notification | |
async scheduleNotification(data: Transaction) { | |
let notifications: Notification[] = []; | |
notifications = await this.storage.get(LocalStorage.NOTIFICATIONS); | |
let firstNotificationTime = new Date(data.dueOn); | |
firstNotificationTime.setDate(firstNotificationTime.getDate()); | |
firstNotificationTime.setHours(21); | |
firstNotificationTime.setMinutes(23); | |
firstNotificationTime.setSeconds(0); | |
const id = random(1, 1000); | |
let notification = { | |
id: id, | |
title: 'Due Today', | |
text: `Payment for ${data.category.name}: ${data.description} of ${Number(data.totalPrice).toLocaleString()} is due today.`, | |
data: { transaction: data }, | |
at: firstNotificationTime, | |
} | |
if (notifications == null) notifications = []; | |
notifications.push(notification); | |
this.storage.set(LocalStorage.NOTIFICATIONS, notifications); | |
this.scheduleNotifications(notifications); | |
} | |
scheduleNotifications(notifications: Notification[]) { | |
cordova.plugins.notification.local.clearAll((res) => { | |
let notificationsDesc = notifications.map((notification) => { | |
return { | |
id: notification.id, | |
title: notification.title, | |
text: notification.text, | |
data: notification.data, | |
trigger: { at: notification.at } | |
} | |
}); | |
console.log(notificationsDesc); | |
cordova.plugins.notification.local.schedule(notificationsDesc); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment