【问题标题】:iOS 10: How to repeat local notification once fired on particular date?iOS 10:如何在特定日期触发后重复本地通知?
【发布时间】:2017-01-21 04:38:10
【问题描述】:

我想在特定日期创建本地通知,然后在本地通知被触发后每 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)

另一个问题:如何设置多个警报来完成相同的结果?

例子:

Alarm1:1/21/2017 @ 8:30am -> 每 30 秒重复一次

Alarm2:1/22/2017 @ 8:32am -> 每 30 秒重复一次 ... 以此类推。

最好的策略是什么?

【问题讨论】:

标签: ios swift


【解决方案1】:

我认为您需要设置两个UNCalendarNotificationTrigger。我假设您想在用户没有响应时每 30 秒重复一次。

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

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

到目前为止,没有一个 UserNotificationTrigger 允许在不同的内部重复而不用户响应通知。

【讨论】:

  • 你回答了我的部分问题。我想要的是类似于 Alarmify 的东西,一旦警报在早上 8:30 触发,它就会一直重复,直到用户停止警报。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多