【发布时间】:2013-03-07 16:29:59
【问题描述】:
用户阅读后,我需要从通知中心清除推送通知。我知道有 cancelAllLocalNotifications 方法,但是如何清除所有远程通知? 作为补充,我希望有以下功能,如果用户在通知中心有 5 条消息,我们只有在用户阅读所有通知后才会清除所有通知。任何想法如何实现这些?提前感谢您的帮助。
【问题讨论】:
标签: ios push-notification
用户阅读后,我需要从通知中心清除推送通知。我知道有 cancelAllLocalNotifications 方法,但是如何清除所有远程通知? 作为补充,我希望有以下功能,如果用户在通知中心有 5 条消息,我们只有在用户阅读所有通知后才会清除所有通知。任何想法如何实现这些?提前感谢您的帮助。
【问题讨论】:
标签: ios push-notification
如果你想快速清除通知
import UserNotifications
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.removeAllPendingNotificationRequests() // To remove all pending notifications which are not delivered yet but scheduled.
center.removeAllDeliveredNotifications() // To remove all delivered notifications
}
【讨论】:
您可以使用setApplicationIconBadgeNumber 清除它们,例如:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
【讨论】: