UNUserNotificationCenter.current().getDeliveredNotifications只返回一个空数组

Bry*_*pel 6 xcode ios swift

基本上,我只是尝试打印我的应用程序提供的通知,但执行以下操作:

UNUserNotificationCenter.current().getDeliveredNotifications { (notifications) in
    print(notifications)
}
Run Code Online (Sandbox Code Playgroud)

只是在Xcode控制台中显示一个空数组,即使通知中心包含多个已发送的通知.(print(notifications.count)返回0)

我可以使用getPendingNotificationRequests成功获取已安排但未送达的通知,更新它们,甚至删除它们removePendingNotificationRequests(withIdentifiers:).但任何访问/修改/删除任何已交付的东西的尝试都不起作用.

我错过了一些简单的东西吗?iOS 10+访问交付的通知的方式最近有什么变化吗?

Tho*_*mon 5

我的确遇到了同样的问题getDeliveredNotification,通知数组始终为空。

因此,我意识到我将设置[UIApplication sharedApplication].applicationBadgeNumber0,可以清除通知中心中的所有远程通知。

现在,我仅在收到所有待处理的通知后设置applicationBadgeNumber0