I have been searching online to see if the notifications that you have scheduled get deleted after the device reboots. I have found mixed opinions, so I've begun testing it. This is what I noticed:
- I have scheduled notifications in 10 minutes, restarted my phone: nothing comes up
- But, yesterday I scheduled a lot of notifications, and some of them were for the current day. Even though since yesterday I've rebooted my phone a lot of times, these notifications do come up.
Below there is a snippet of code which I used to do the scheduling:
let notificationContent = UNMutableNotificationContent()
notificationContent.body = "This is a notification"
notificationContent.categoryIdentifier = NotificationContentProvider.snoozeCategoryIdentifier
let unitFlags = [.hour, .minute, .second, .day, .month, .year] as [Calendar.Component]
let components = Calendar.current.dateComponents(Set(unitFlags), from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: false)
let request = UNNotificationRequest(identifier: "\(Int.random())", content: notificationContent, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: { (error) in
if let theError = error {
print(theError.localizedDescription)
}
})