Example Case
User sets a reminder at 1:00 PM, repeating every day. I schedule 7 notifications, 1 for each weekday, each repeating. The user should get a notification every day at 1:00 PM unless they turn off the feature.
Problem
After successfully scheduling local notifications, and it working for the first day, the notifications stop working and printing pending notifications shows that they mysteriously got unscheduled.
What I know
I've heard of a 64 limit to notifications, but when testing with 7 notifications (1 reminder for each day of the week, repeating) it doesn't work either.
Each notification has an ID in the format:
Code Block <my bundle id>.<UUIDstring>
It consistently works on the first day, then fails on the 2nd or 3rd day
The app is in production, the problem occurs in both development and production environments.
Code
Code Block swift for day in self.days { /* days is an array of integers representing weekdays */ let content = UNMutableNotificationContent() content.title = "Practice \(profile.name)" content.categoryIdentifier = "reminder" content.sound = UNNotificationSound.default var dateComponents = DateComponents() dateComponents.weekday = day dateComponents.hour = Calendar.current.component(.hour, from: self.date) dateComponents.minute = Calendar.current.component(.minute, from: self.date) dateComponents.second = 0 let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true) /* id(for:) generates a unique id using a UUID and the weekday. */ let request = UNNotificationRequest(identifier: id(for: day), content: content, trigger: trigger) center.add(request) { (error) in print(error) /*never an error here*/ } }
The code seems to work exactly as intended; printing pending notifications shows 7 repeating notifications on different days as expected. However after a few days it stops working, and printing pending notifications shows no pending notifications.
I really need to get this resolved. Any ideas?