如何在 iOS 中检查状态栏中哪些通知处于活动状态?

iosapps/applicationsmobile development更新于 2026/2/15 13:22:17

要获取状态栏托盘中处于活动状态的通知列表,我们将使用 getdeliverednotifications,您可以在此处阅读更多相关信息。

https://developer.apple.com/documentation/usernotifications/unusernotificationcenter

https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/1649520-getdeliverednotifications

虽然我们知道我们无法获取所有应用的通知,因为这会侵犯隐私,但我们可以获取我们应用的通知。

Apple 提供了 getDeliveredNotifications(completionHandler:)

该方法返回仍在通知中心显示的应用通知列表。

您可以根据需要编写以下代码。

UNUserNotificationCenter.current().getDeliveredNotifications { (notifications) in
   print(notifications)
}

相关文章