【发布时间】:2020-04-16 19:05:45
【问题描述】:
有没有办法安排在特定日期触发并每分钟重复一次的本地通知? 示例:用户在上午 8:00 收到第一个通知,然后是 8:01、8:02...
【问题讨论】:
标签: ios swift notifications unnotificationrequest unnotificationtrigger
有没有办法安排在特定日期触发并每分钟重复一次的本地通知? 示例:用户在上午 8:00 收到第一个通知,然后是 8:01、8:02...
【问题讨论】:
标签: ios swift notifications unnotificationrequest unnotificationtrigger
要安排重复通知,您需要在触发器初始化中使用日期组件。
例如
let date = Date(timeIntervalSinceNow: 3600)
let triggerDaily = Calendar.current.dateComponents([.hour,.minute,.second], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDaily, repeats: true)
触发器每天重复通知
尝试在日期组件中仅使用 .second 设置触发器
let date = Date(timeIntervalSinceNow: 3600)
let triggerDaily = Calendar.current.dateComponents([.second], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDaily, repeats: true)
【讨论】: