【发布时间】: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 秒重复一次 ... 以此类推。
最好的策略是什么?
【问题讨论】:
-
根据developer.apple.com/reference/usernotifications/…
UNCalendarNotificationTrigger(dateMatching: newComponents, repeats: true)可能会有所帮助 -
例如每天 8:30 重复。不是在上午 8:30 之后每 30 秒一次。