I want to set a repeat Local notification from date. For Example:
StartDate: 25 June 2018
Todays Date: 21 June 2018
I am stuck here. Below code is working but it is firing local notification from today not from 25 June 2018.
Please have a look to my Local Notification function:
func scheduleDosageLocalNotification(date: Date) {
reminder.dosageIdentifier = "Dosage_Day"
var calendar = Calendar.current
calendar.timeZone = TimeZone.current
let notificationContent = UNMutableNotificationContent()
// Configure Notification Content
notificationContent.title = "DOSAGE REMINDER"
notificationContent.body = "Remember to take your TEST tablet dialy."
// Set Category Identifier
notificationContent.categoryIdentifier = Notification.Category.First
var components = calendar.dateComponents([.hour, .minute], from: date)
components.hour = 08
components.minute = 00
let notificationTrigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true)
// let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: interval!, repeats: true)
// Create Notification Request
let identifier = "Dosage_Day"
let notificationRequest = UNNotificationRequest(identifier: identifier, content: notificationContent, trigger: notificationTrigger)
// Add Request to User Notification Center
UNUserNotificationCenter.current().add(notificationRequest) { (error) in
if let error = error {
print("Unable to Add Notification Request (\(error), \(error.localizedDescription))")
}
Utilities.saveContextForAppInfo()
}
}
It should repeat daily but from 25th of June. Thanks in Advance!!