0

I want to make an app just like iOS Reminders app. My problem is the custom repeat part. We can set custom repeats like "Every 2 Months on the third Monday"(the screenshot below) but I don't know how to implement this sort of repeats with User Notification.

What should I have do?

screenshot

Micho
  • 3,929
  • 13
  • 37
  • 40
Sanhood
  • 11
  • 1
  • This might help you https://developer.apple.com/documentation/usernotifications – swetansh kumar Nov 02 '17 at 08:54
  • It's hard to implement, I'm not recommended to use. However you can set the notification for every day, every week, every year, every weekdays. It's just works – Mannopson Nov 02 '17 at 12:57

1 Answers1

1

Although the question might be abroad to be fully answered, I would post an answer that should scratch the surface of how you could achieve it by using user notifications.

If you are aiming to let the displaying of the notification is based on a specific date/interval -as you mentioned "Every 2 Months on the third Monday"-, then you should work with UNCalendarNotificationTrigger:

The date and time at which to deliver a local notification.

Example:

import UserNotifications

// first, you declare the content of the notification:
let content = UNMutableNotificationContent()
content.title = "Notification Title"
content.subtitle = "Notification Subtitle"
content.body = "Notification Body"

// now, you should declare the UNCalendarNotificationTrigger instance,
// but before that, you'd need to describe what's the date matching for firing it:

// for instance, this means it should get fired every Monday, at 10:30:
var date = DateComponents()
date.weekday = 2
date.hour = 10
date.minute = 30

// declaring the trigger
let calendarTrigger = UNCalendarNotificationTrigger(dateMatching: date, repeats: true)

// creating a request and add it to the notification center
let request = UNNotificationRequest(identifier: "notification-identifier", content: content, trigger: calendarTrigger)
UNUserNotificationCenter.current().add(request)
Ahmad F
  • 30,560
  • 17
  • 97
  • 143
  • Hey Ahmad! We are pretty stuck over here on an issue. We are trying to make repetitive notification with different body for each time it fires. Can we update the notification body even if the user doesn't opens the app? – Roi Mulia Mar 20 '18 at 12:55
  • @RoiMulia there is no doubt that you should be able to do such a thing. It depends on how would you create the triggers. Note that `UNCalendarNotificationTrigger` contains `repeats: true` in its initializer which means that you could fire it only once, therefore add many triggers without any repeating... – Ahmad F Mar 20 '18 at 15:20
  • Can we update existing one tho or we have to create a new one? – Roi Mulia Mar 20 '18 at 15:34