I was trying to set up local notifications to fire on the last day of each month regardless of whether it's the 28th, 29th, 30th, or 31st.
With the previous framework UILocalNotification I could specify the fireDate and repeatInterval and it worked. But now that I'm updating the framework to UNNotofication, I tried to use UNCalendarNotificationTrigger and set the DateComponents' day to 0. However it didn't fire. Anything I was doing wrong? Thanks!
The code is as below. nextTriggerDate is nil.
var components = DateComponents()
components.hour = 8
components.minute = 0
components.day = 0
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true)
print(trigger.nextTriggerDate())
You can use the following code, next last day month is calculated after notification is shown.
I have tested it, working fine for me.