如何修复 macOS 应用程序中重复的重复通知问题

问题描述

我在 macOS 应用程序中使用以下代码创建了一个 UNNotificationRequest

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
}

我希望通知在 2021 年的每个月 24 日触发。

通知被触发时,它每秒生成重复的重复通知。 如果我将 datecomponents 中的 year 属性设为 nil,则不会生成重复的重复通知

但我需要根据我的要求设置年份属性。我在示例 iOS 应用程序中尝试了相同的代码。它不会生成重复的通知。它仅在 macOS 应用中生成

如果我在 datecomponents 中设置了 year 属性不生成重复的重复通知解决方案是什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)