如何解决取消仅今天重复的UNNotification
我通过设置小时,分钟和秒来安排每日重复通知:
func addNotification(fireDate: Date)
{
let notificationCenter = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = "Some title"
content.body = "Some message"
content.sound = .default
content.categoryIdentifier = "MyCategory"
let calendar = Calendar(identifier: .gregorian)
let triggerDate = calendar.dateComponents([.hour,.minute,.second],from: fireDate)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate,repeats: true)
let requestID = UUID().uuidString
let notificationRequest = UNNotificationRequest(identifier: requestID,content: content,trigger: trigger)
notificationCenter.add(notificationRequest) { error in
if let error = error
{
print(error.localizedDescription)
}
}
}
现在,我希望能够取消当天的所有通知,因此我可以从明天开始接收通知。我尝试将UNCalendarNotificationTrigger子类化以更改nextTriggerDate,但是使用自定义触发器类添加通知时出现错误。无法找到实现此目的的方法,如果我在特定时间取消计划的通知,我将不再收到该通知。任何想法都表示赞赏。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。