4

I'm building a reminders app that sends local notifications that repeat based on a user's custom settings. For example, I may send a notification every other day at 8pm. Every time I send one of these notifications, I'd like to replace any previous notification that might be displayed in the user's notification center already.

The new UserNotifications framework in iOS gets me close to being able to do this. As far as I can tell, notifications can be replaced in two ways:

  1. Use a UNCalendarNotificationTrigger with repeats: true. Repeated triggers replace past ones.
  2. Create a new UNNotificationRequest with the same identifier. Whenever a request is sent with the same identifier, it replaces all other instances.

Neither of these solutions quite work for me:

  1. I can't use use repeating notifications because UNCalendarNotificationTrigger uses DateComponents for a repeating schedule which just isn't granular enough. My example above of "every other day at 8pm" can't be described with just DateComponents.
  2. Because I need to schedule several notifications all at once, I must specify unique identifiers, and as such, they don't replace each other when displayed.

I was hoping service extensions would save me here. If I could execute code when I receive a notification, I could programmatically remove old notifications when new ones are triggered. Unfortunately, it appears as if service extensions only work for remote notifications. Even if I could use remote notifications (which is a whole can of worms by itself), this solution kind of bends the rules on what is allowed for service extensions.

Does anyone have any ideas on how to solve this, or am I destined to spam my users' notification centers?

Brent Traut
  • 5,614
  • 6
  • 29
  • 54
  • This doesn't help at all and your link dump is on the order of spam. It just tells me how to subscribe to notification events when my app is already running and doesn't mention any interactions with already-displayed notifications. – Brent Traut Sep 29 '16 at 18:38
  • I have exactly the same question, did you get anywhere with this? – RJB May 03 '18 at 20:17
  • Never found a solution, but I admit I stopped looking after a short period of time. Hopefully you have better luck! – Brent Traut May 03 '18 at 23:43

0 Answers0