【发布时间】:2017-02-13 17:21:10
【问题描述】:
我正在使用以下方法来获取每小时触发的本地通知。
let reminderTrigger = UNCalendarNotificationTrigger.init(dateMatching: NSCalendar.current.dateComponents([.minute], from: dateStart), repeats: true)
let notificationRequest = UNNotificationRequest(identifier: "reminder", content: reminderContent, trigger: reminderTrigger)
这是基于 Apple 在此处的文档 - https://developer.apple.com/reference/usernotifications/uncalendarnotificationtrigger
但是,当我打印下一个触发日期时,就完全错误了。
print(dateStart)
print(reminderTrigger.nextTriggerDate())
这是输出 -
2016-09-10 05:18:58 +0000
Optional(2016-09-11 04:00:06 +0000)
不过应该是
2016-09-10 06:00:00 +0000
我以类似的方式尝试了每日、每周、每月、每年,它们都返回正确的下一个触发日期。每小时是唯一看起来不正确的。有什么想法吗?
【问题讨论】:
-
我遇到了类似的问题,唯一的区别是唯一的偏移量不正确,即使在日期组件对象上设置
timeZone也是如此。当日期到达时,通知不会被触发,但它也不会列在待处理或已发送的通知中。 -
您的时区/日历设置肯定有问题。如果您不指定小时,它会自动设置为默认值,因此无论您的设备设置如何,它都有效。