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