Swift-带有完成处理程序的getDeliveredNotifications在第一次通知时给出一个空数组

Mar*_*rco 6 ios swift unusernotificationcenter

我有以下代码:

let center = UNUserNotificationCenter.current()

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

    center.getDeliveredNotifications { (delivered) in
        print(delivered.count)
    }
    completionHandler([.alert, .badge])
}
Run Code Online (Sandbox Code Playgroud)

我试图弄清楚在传递第一个通知时传递的是一个空数组。这意味着,例如,如果安排了2条通知,则第一个到达时将打印(0),然后第二个到达时将打印(1)。

有谁知道为什么这样的行为?我正尝试在通知发送后立即对其进行计数。谢谢!