首页 文章

iOS 10:如何在特定日期触发后重复本地通知?

提问于
浏览
2

我想在特定日期创建本地通知,然后在本地通知被解雇后每30秒重复一次 . 这是我的代码:

let calendar = Calendar(identifier: .gregorian)
let components = calendar.dateComponents(in: .current, from: date)
let newComponents = DateComponents(calendar: calendar, timeZone: .current, month: components.month, day: components.day, hour: components.hour, minute: components.minute)
let trigger = UNCalendarNotificationTrigger(dateMatching: newComponents, repeats: false)
let request = UNNotificationRequest(identifier: ID, content: content, trigger: trigger)

另一个问题:如何设置多个警报以实现相同的结果?

例:

闹1:2017年1月21日上午8:30 - >每30秒重复一次

闹2:1月22日上午8:32 - >每30秒重复一次......等等 .

这样做的最佳策略是什么?

1 回答

  • 0

    我想你需要设置两个 UNCalendarNotificationTrigger . 我假设你想在用户没有回复时每30秒重复一次 .

    一个在 Alarm1: 1/21/2017 @ 8:30:00 ,与 repeat: false . 并在 1/21/2017 @ 8:30:30repeat: true 添加第二个 UNCalendarNotificationTrigger .

    当用户对第一个通知的响应时,您可以删除第二个 UNCalendarNotificationTrigger .

    到目前为止,没有 one UserNotificationTrigger 允许在不同的内部重复,而无需用户响应通知 .

相关问题