1

I Know, This may be [duplicate question][1]. I tried so many solutions but no one solution meet my expectation. Here is my scenario.

Notification StartDate: 26-July-2022

Today's Date: 23-July-2022

I want to set a repeat Local notification from a certain start date.

Here is my Code :

func scheduleLocalNotification(startDate: Date) {
    var calendar = Calendar.current
    calendar.timeZone = TimeZone.current
    
    let content = UNMutableNotificationContent()
    content.title = "REMINDER For Yoga"
    content.body = "Hi! Get ready for Daily Yoga Class."
    content.categoryIdentifier = "Yoga_872"
    
    let components = calendar.dateComponents([.hour, .minute], from: startDate)
    let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true)
    

    let identifier = "Yoga_Class(222)"
    let notificationRequest = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
    
    // Add Request to User Notification Center
    UNUserNotificationCenter.current().add(notificationRequest) { (error) in
        if let error = error {
            print("Add Notification Request Error:  (\(error), \(error.localizedDescription))")
        }
    }
    
}

This code is firing notification from today not from Start date (26-July-2022). [1]: Set repeat Local notification from date

Ashu
  • 3,373
  • 38
  • 34
  • 1
    Short answer. You can't. You need to schedule a series of notifications, each one day apart. There is a limit to how many you can schedule (about 20 from memory). Each time your app is opened you can calculate what notifications to schedule. If it is after the notification start date then you can cancel the remaining scheduled notifications and schedule a single, daily repeating notification. – Paulw11 Jul 23 '22 at 13:00
  • But So many Apps doing this – Ashu Jul 23 '22 at 13:09
  • And they would all be either scheduling multiple notifications or using push notifications. You just can't combine daily repeating notification and start on a specific date triggers. – Paulw11 Jul 23 '22 at 13:27

0 Answers0