更新:
我需要找到下一个通知请求和相关的 ID,所以我最终选择了这个:
UNUserNotificationCenter.current().getPendingNotificationRequests {
(requests) in
var requestDates = [String:Date]()
for request in requests{
let requestId = request.identifier
let trigger = request.trigger as! UNCalendarNotificationTrigger
let triggerDate = trigger.nextTriggerDate()
requestDates[requestId] = triggerDate
}
let nextRequest = requestDates.min{ a, b in a.value < b.value }
print(String(describing: nextRequest))
}
我认为这种方法可能会提供更优雅的解决方案,但正如 Duncan 在下面指出的 UNNotificationRequests 不可比:
requests.min(by: (UNNotificationRequest, UNNotificationRequest) throws -> Bool>)
如果有人有更好的解决方案,请告诉我。