Restructured Notification. Added BulkSchedueling
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user