Reputation: 3218
my app has to remind the user of something every n days.
Currently, I have
var dateComponents = DateComponents()
dateComponents.hour = userHour
dateComponents.minute = userMinute
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
My problem is that I don't know how to express the skipping of dates with DateComponents.
I've found UNTimeIntervalNotificationTrigger
which allows me to set it off every 24 or 48 etc. hours but this give me the possibility to fire at a certain daytime.
Should I mix those 2? First set the Calendar trigger and in the first notification make it actually repeat? Doesn't seem right to me, there must be an easier way.
Upvotes: 1
Views: 1606
Reputation: 514
I've looked quite deeply into iOS local notifications and there are some things that are weirdly absent. This is one of those things as far as I know.
If you don't need to set a specific time for the notification to fire you can use the UNTimeIntervalNotificationTrigger which would allow you to set a notification every 72 hours from the time you set it.
If you need and exact time for the notification to go off you could use your code but add dateComponents.weekday and set 1 and 4 or whatever. Which isn't perfect but might work for what you need.
A solution that will take a lot more work would be to create like 5 notifications. Set the day and time you want them to fire (3 days away, 6 days, 9 days, etc) Then when the user launches the app you look to see if any of the notifications have been sent and set them again in the future. These would not be repeating. It's up to you to manually set them each time.
Upvotes: 3