I have an app that delivers local notifications after a set time to remind people to take a break. What I'd like to also have is the app to display the time when the next break will be. But I'm not sure how to have the time automatically update once the set time between notifications is done (if they set them to happen every two hours, to have the next reminder time update to another two hours).
I can do the first one easily:
var nextReminder = Date().addingTimeInterval(TimeInterval(timeInSeconds))
Time in seconds is already calculated from what the user selected from a circular slider, not sure if the code is necessary here though (let me know if it is.)
What I'm not sure how to do is to repeat it at an interval of timeInSeconds (whatever it is) and update the new time. Is it possible to repeat that without a for loop and arrays? This is my first attempt at a SwiftUI app.
This is how the next reminder is displayed:
VStack{
Text("Next reminder at:")
.font(.system(size: 28))
.bold()
.padding(.bottom, 3)
Text("\(nextReminder, style: .time)")
.font(.system(size: 20))
Text("\(nextReminder, style: .date)")
}
I have a button to start sending the notifications. The sending of notifications and everything works properly with a repeating trigger for that. What I'd like is for it to start repeating for the next reminder once the button is tapped.
Button("Start new reminders"){
notify.sendNotification(
date: Date(),
type: "time",
timeInterval: Double(timeInSeconds),
title: "Take a break!",
body: "This is your reminder to do something else.")
if timeInSeconds < 3599 {
timeAlert = true
}
if timeInSeconds > 3599 {
successAlert = true
}
print("\(timeInSeconds) time")
}
timeAlert and successAlert just say if the timer was long enough to start for the repeat (over 60 minutes).