-2

I'm trying to create a local notification in swift every 28 days starting from a given date. For example, if the user enters the date 2020/01/31, I need to create a local notification on 2020/02/28 and so on. How do I do it using Swift 4 in Xcode 11?

  • 2
    have you tried anything yet? show your code. Also read this tutorial to learn how to schedule notifications : https://medium.com/quick-code/local-notifications-with-swift-4-b32e7ad93c2 – Keshu R. Feb 18 '20 at 08:44

1 Answers1

2

Once, you can calculate the date which is 28 days after :

let formatter = DateFormatter()
    formatter.dateFormat = "dd.MM.yyyy"
    let calculatedDate = formatter.date(from: yourDate)
    let notificationTime = Calendar.current.date(byAdding: .day,value: 28,to: calculatedDate)!

And compare it to date which you want. If equals set notification.

Hope it helps...

Picode
  • 1,140
  • 1
  • 6
  • 12