微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何修复 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 举报,一经查实,本站将立刻删除。