UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

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.