0

In iOS 11, how can I implement a local notification which repeats every x minutes?

The repeating interval will be selected from the user. So for example let's say that a user choose to set a notification which will trigger tomorrow at 9:00 AM and from there it triggers every 2 days (or two weeks or 6 months or 10 minutes)

var repeatInterval = Bool()

trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate, repeats: repeatInterval)

//Schedule the Notification
let identifier = titleNospace
let request = UNNotificationRequest(identifier: identifier!, content: content, trigger: trigger)
self.center.add(request, withCompletionHandler: { (error) in
    if let error = error {
        print(error.localizedDescription)
    }
})
UNUserNotificationCenter.current().add(notificationRequest, withCompletionHandler: nil)

With this code I can schedule a notification at a set date. I've been told that from here if I would like to schedule a repeat notification I should use a triggerInterval when the notification is delivered. But how can I do so? How can I get the value of the repeating time (defined by the user) when the notification is delivered? Shall I use this?:

func didReceive(_ notification: UNNotification)

I've tried but it seems that it's never called.

I'm new to swift and I've tried and tried but it seems I cannot find a solution. I've been able to manage the repeating hourly, monthly, daily and yearly. If I would like to add a custom repeat though I really wouldn't know how to do.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Marco
  • 1,051
  • 1
  • 17
  • 40

1 Answers1

0

For your information you can't do customise repeat time interval like every 2 min, 10 min or Etc. you must use value of NSCalendarUnit like

How to set repeat frequency in User Notification

Govaadiyo
  • 5,644
  • 9
  • 43
  • 72
  • and it does not explain hot to set custom interval... i've been able to set hourly daily monthly.... i was looking on how to set custom interval... it does' have to be a way to set it... – Marco Sep 07 '17 at 12:38