0

I have created a UNNotificationRequest with following code in a macOS app

let content = UNMutableNotificationContent()
        
content.title = "Welcome"
content.body = "body"
content.sound = UNNotificationSound.default
                                
var dateComponent = DateComponents()
        
dateComponent.year = 2021
dateComponent.day = 24
dateComponent.hour = 12
dateComponent.minute = 27
        
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponent, repeats: true)
       
let request: UNNotificationRequest = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
        
UNUserNotificationCenter.current().add(request) { (error) in
}

I want the notification to trigger on 24th of every month in 2021.

When the notification is triggered, it generates repeated duplicate notifications every second. If I make the year attribute in datecomponents to nil, then it does not generate repeated duplicate notifications.

But I need to set the year attribute according to my requirement. I tried the same code in a sample iOS app. It does not generate duplicate notifications. It generates only in macOS app.

What is the solution for not generating repeated duplicate notifications if I set the year attribute in datecomponents?

asdfg
  • 3
  • 4

0 Answers0