OGeek|极客世界-中国程序员成长平台

标题: ios - 具有每周重复和特定开始日期的通知 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:41
标题: ios - 具有每周重复和特定开始日期的通知

我可以将 UNNotification 设置为在特定日期/时间触发,就像这样

let components = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: fireTime)
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: false)

我可以设置一个在一周中特定日期的特定时间触发,每周,就像这样

var components = Calendar.current.dateComponents([.weekday], from: nextMondayDate)
components.setValue(10, for: .hour)
let trigger = UNCalendarNotificationTrigger.init(dateMatching: triggerComps, repeats: true)

但是有什么方法可以设置 UNNotification 在特定日期和时间触发,然后每周在该工作日和时间重复?

具体来说,我想将通知设置为每周一上午 10 点触发除了下周一。



Best Answer-推荐答案


如果您只想跳过下周一,您可以计算下周一的下一个日期并在组件中设置 nextMondayDate 的位置保持其余设置不变,如重复 true .

关于ios - 具有每周重复和特定开始日期的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48540447/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4