问题描述
我通过设置小时,分钟和秒来安排每日重复通知:
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 (将#修改为@)