d7laungani / DLLocalNotifications

:speech_balloon: Easily create Local Notifications in swift - Wrapper of UserNotifications Framework
MIT License
214 stars 38 forks source link

Fire Notification Daily but After a certain date #36

Open ErAshu opened 2 years ago

ErAshu commented 2 years ago

I want to set a repeat Local notification from date. For Example:

StartDate: 26-July-2022

Todays Date: 23-July-2022

I am stuck here. I want to set a repeat Local notification from date.

Please have a look to my Notification function:

func scheduleLocalNotification(date: Date) {
        var calendar = Calendar.current
        calendar.timeZone = TimeZone.current

        let content = UNMutableNotificationContent()
        // Configure Notification Content
        content.title = "REMINDER For Yoga"
        content.body = "Hi! Take ready for Daily Yoga Class."

        // Set Category Identifier
        content.categoryIdentifier =  "Yoga_872"
        var components = calendar.dateComponents([.hour, .minute], from: date)

        let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true)

        // Create Notification Request
        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 function fire notification from Today. I want to this from 26th July 2022.