BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

Local Notifications with specified start date and repeatable every 3 days

Forums > Swift

Hi,

I have been trying to simply make the app to send local notifications and it has been fine for like sending it out daily or weekly or monthly by using UNCalendarNotificationTrigger and set repeat to true.

But how can I set the notification to be sent for like every 3 days with a future start date?

UNTimeIntervalNotificationTrigger seems to be only work for start date as of now....not from a futute date..

Thanks, Newbie

2      

You could try using UNTimeIntervalNotificationTrigger instead. The range goes upto 10000 years.

From the Xcode documention here is an example.

// Fire in 30 minutes (60 seconds times 30)
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: (30*60), repeats: false)

I believe that if you set repeat to true then it would repeat at whatever time interval is set to (in the above case 30 * 60). So you might need to set up two notifications - the first for the initial arbitary future date, and once that has passed a second notification for the repeating notification every 3 days.

A couple of things to note is that a user can at any time remove the permissions for notification, so you will have to handle that situation for both cases. Also you will need to cancel the notifications once the user acknowledges it.

also from the Xcode documentation (for init(timeInterval:repeats:))

If you specify true for the repeats parameter, you must explicitly remove the notification request to stop the delivery of the associated notification. Use the methods of UNUserNotificationCenter to remove notification requests that are no longer needed.

You may want to also have a look at these tutorials - Local Alerts Using UNNotificationCenter and Project 21: Local Notifications

2      

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.