2

I can set a UNNotification to fire at a specific date/time, like so

let components = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: fireTime)
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: false)

And I can set one to fire at a specific time on a specific day of the week, every week, like so

var components = Calendar.current.dateComponents([.weekday], from: nextMondayDate)
components.setValue(10, for: .hour)
let trigger = UNCalendarNotificationTrigger.init(dateMatching: triggerComps, repeats: true)

But is there any way I can set a UNNotification to fire at a specific date and time, and then to repeat every week on that weekday and time?

Specifically, I would like to set a notification to fire every Monday at 10am except next Monday.

James White
  • 774
  • 1
  • 6
  • 18
  • BTW: Same problem here https://stackoverflow.com/questions/41449749/how-can-i-skip-the-first-occurrence-of-a-repeating-uncalendarnotificationtrigger and here https://stackoverflow.com/questions/44872429/scheduling-local-notifications-to-repeat-daily-from-tomorrow-in-swift?noredirect=1&lq=1 no simple answers, only possible hacks. This seems to be clearly a missing feature... – user2782993 Jan 31 '18 at 12:38
  • 1
    I found this as a soultion: https://stackoverflow.com/questions/54076050/repeat-interval-for-unnotification/54076269#54076269 – Brooketa Jan 16 '19 at 13:28

1 Answers1

0

if you just want to skip only next monday, you can calculate next to next monday date and set in the components on the place of nextMondayDate keeping rest of the setting as it is, like repeat true.

Van
  • 1,225
  • 10
  • 18
  • It doesn't matter what specific date goes in the place of nextMondayDate, because the dateComponents only uses the .weekday component from that date. That's what the repeat is based on. If you were to use the .year .month and .day components, you wouldn't get a weekly repeat. – James White Jan 31 '18 at 11:56