Reputation: 23
I want to develop a reminder app that need to send local notification when we set the reminder. I developed some code that triggers only one notification even i set multiple notifications. if i set reminders at 7:30 PM, 7:31 PM, 7:32 PM, the notification is showing only at 7:32PM.
Here is my code
func scheduleNotification(at date: Date) {
let calendar = Calendar(identifier: .gregorian)
let components = calendar.dateComponents(in: .current, from: date)
let newComponents = DateComponents(calendar: calendar, timeZone: .current, month: components.month, day: components.day, hour: components.hour, minute: components.minute)
let trigger = UNCalendarNotificationTrigger(dateMatching: newComponents, repeats: true)
let content = UNMutableNotificationContent()
content.title = "Reminder"
content.body = "To day is the last date for the payment of your card. Please make payment today."
content.sound = UNNotificationSound.default()
content.categoryIdentifier = "PaymentReminderIdentifier"
let request = UNNotificationRequest(identifier: "ReminderNotification", content: content, trigger: trigger)
UNUserNotificationCenter.current().delegate = self
//UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print("Uh oh! We had an error: \(error)")
}
}
}
//
func notif() {
let selectedDate = fullDate
print("Selected date: \(selectedDate)")
let delegate = UIApplication.shared.delegate as? AppDelegate
delegate?.scheduleNotification(at: selectedDate!)
}
i want to deliver notifications every time when i create the reminder. help me to resolve this problem. thank you...
Upvotes: 2
Views: 1865