Tai
Tai

Reputation: 25

How to Reset Local Notifications when App Re-opens

I am developing a reminder app with custom Repeat Intervals for local notifications. What I basically want is the DueDate notification to fire then subsequent notifications fire afterwards.

So Notification1.fireDate = the DueDate.date

Notification2.fireDate = DueDate.date.dateByAdding(1000)

& continue for 10 or so times. Then when the app becomes active again, I want the line of notifications to loop again but start after the last notification, like a Queue.

This is all to create the illusion of custom repeat intervals. This is where I got the idea from, so it can be done https://stackoverflow.com/a/5765870/5601784

Upvotes: 0

Views: 552

Answers (1)

snjmhj
snjmhj

Reputation: 1081

If you are not changing the fireDate, then there is no point in deleting the previously set notification and setting it again. However, to delete all the notification that your app has set you can do this.

UIApplication.shared.cancelAllLocalNotifications()

or

let app: UIApplication = UIApplication.shared
for event in app.scheduledLocalNotifications! {
  let notification = event as UILocalNotification
  app.cancelLocalNotification(notification)
}
print(app.scheduledLocalNotifications!.count))//prints -- 0

Then you can set the UILocalNotification with the new information.

Upvotes: 1

Related Questions