My goal is to set up a repeating daily reminder notification. The following code always successfully show the notification once, but does not repeat it, despite setting repeat: true
in the code.
The entire notification code is below:
let notificationID = "daily_sleep_alarm"
let title = "Rest your weary eyes"
let body = "It's bedtime. The comfort of your blanket beckons you."
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [notificationID])
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = title
content.body = body
content.categoryIdentifier = "daily_sleep_alarm"
content.userInfo = ["customData": "fizzbuzz"]
content.sound = nil
var dateComponents = DateComponents()
dateComponents.hour = hourSelected
dateComponents.minute = minuteSelected
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
let request = UNNotificationRequest(identifier: notificationID, content: content, trigger: trigger)
center.add(request)
As noted above, this code does not successfully show the notification after once. I have no other code that clears pending notifications with this particular notificationID
.
On app start, I also check to see what pending notifications are available with center.getPendingNotificationRequests
, and it always shows as none.
Any insights on what I need to do to correctly set up the daily repeating notification is muched appreciated.
i'm just using this simple lines of code for daily