确认的。我运行了这段代码:
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 120, repeats: true)
print("scheduling at", Date())
DispatchQueue.main.asyncAfter(deadline: .now()+15) {
print("checking at", Date())
UNUserNotificationCenter.current().getPendingNotificationRequests {
arr in let arr = arr
if let req = arr[0].trigger as? UNTimeIntervalNotificationTrigger {
let fd = req.nextTriggerDate()
print("trigger date", fd as Any)
}
}
}
// ... proceed to configure and schedule the notification
我还配置了我的用户通知中心委托以在前台接收通知并打印时间。
这是我在控制台中看到的内容:
scheduling at 2018-08-01 03:40:36 +0000
checking at 2018-08-01 03:40:51 +0000
trigger date Optional(2018-08-01 03:42:51 +0000)
received notification while active 2018-08-01 03:42:36 +0000
因此,触发日期报告为 2 分钟后当我检查时,但通知实际上是在 2 分钟后触发的当我安排的时候.
我会把它描述为一个错误!
我对你原来的问题的一个不同意见是,我得到了完全相同的结果non-重复UNTimeIntervalNotificationTrigger:
scheduling at 2018-08-01 03:45:50 +0000
checking at 2018-08-01 03:46:06 +0000
trigger date Optional(2018-08-01 03:48:06 +0000)
received notification while active 2018-08-01 03:47:50 +0000
UNTimeIntervalNotificationTrigger 还有一个timeInterval
属性,但即便如此,除非我们知道通知最初安排的时间,而且 UNNotificationRequest 无法提供任何方法来查明这一点。
(为了确定起见,我推迟了检查,直到重复通知触发了几次,但结果是相同的:nextTriggerDate
明确添加了timeInterval
to now而不是报告下次触发通知的时间。)