Restructured Notification. Added BulkSchedueling

This commit is contained in:
Aaron
2021-01-26 22:46:39 -05:00
parent e55736d4d5
commit 65eeea22e8
+20 -9
View File
@@ -10,17 +10,12 @@ import UserNotifications
class Notification { class Notification {
init(alarm: Alarm) { //Removes the notifiation
self.alarm = alarm static func removeNotification(alarm: Alarm) {
}
var alarm: Alarm
func removeNotification() {
UNUserNotificationCenter.current().getPendingNotificationRequests { (notificationRequests) in UNUserNotificationCenter.current().getPendingNotificationRequests { (notificationRequests) in
var identifiers: [String] = [] var identifiers: [String] = []
for notification:UNNotificationRequest in notificationRequests { for notification:UNNotificationRequest in notificationRequests {
if notification.identifier == self.alarm.notificationID { if notification.identifier == alarm.notificationID {
identifiers.append(notification.identifier) identifiers.append(notification.identifier)
} }
} }
@@ -28,7 +23,23 @@ class Notification {
} }
} }
func scheduleNotification() { // Check for duplicates and adds any missing notifications
static func bulkScheduleNotifications(alarms: [Alarm]) {
var ids: [String] = []
UNUserNotificationCenter.current().getPendingNotificationRequests { (notificationRequests) in
for notification:UNNotificationRequest in notificationRequests {
ids.append(notification.identifier)
}
for alarm in alarms {
if !ids.contains(alarm.notificationID) {
scheduleNotification(alarm: alarm)
}
}
}
}
static func scheduleNotification(alarm: Alarm) {
let content = UNMutableNotificationContent() let content = UNMutableNotificationContent()
//Date formatting to string //Date formatting to string