UNCalendarNotificationTrigger每小时触发器返回错误的触发日期

时间:2016-09-10 05:26:45

标签: ios iphone swift ios10

我正在使用以下内容获取每小时触发的本地通知。

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

我以类似的方式尝试了每日,每周,每月,每年,所有这些都会返回正确的下一个触发日期。每小时是唯一一个似乎不正确的。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我遇到了和你一样的问题。

        UNNotificationRequest *request = notifyDict[[NSString stringWithFormat:@"%ld", indexPath.row]];
        UNTimeIntervalNotificationTrigger *trigger = (UNTimeIntervalNotificationTrigger *)request.trigger;
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"HH:mm:ss"];
        NSString *strDate = [dateFormatter stringFromDate:trigger.nextTriggerDate];

我得到了触发器的nextTriggerDate,但日期不是我之前为触发器设置的值。