如何清除应用程序中的远程通知?

2024-03-07

有没有办法从 iPhone 屏幕顶部向下滑动时清除通知横幅中的远程通知。我尝试将徽章编号设置为零:

application.applicationIconBadgeNumber = 0 

代表中didFinishLaunchingWithOptions, and didReceiveRemoteNotification,但它没有清除通知。谢谢。


在 iOS 10 中,以上所有解决方案均已被弃用

'cancelAllLocalNotifications()' 在 iOS 10.0 中已弃用:使用 UserNotifications Framework 的 -[UNUserNotificationCenter removeAllPendingNotificationRequests]

使用以下代码取消通知并重置徽章计数

适用于 iOS 10、Swift 3.0

cancelAllLocalNotifications从 iOS 10 开始已弃用。

@available(iOS, introduced: 4.0, deprecated: 10.0, message: "Use UserNotifications Framework's -[UNUserNotificationCenter removeAllPendingNotificationRequests]")
open func cancelAllLocalNotifications()

您必须添加此导入语句,

import UserNotifications

获取通知中心。并执行如下操作

application.applicationIconBadgeNumber = 0 // For Clear Badge Counts
let center = UNUserNotificationCenter.current()
center.removeAllDeliveredNotifications() // To remove all delivered notifications
center.removeAllPendingNotificationRequests() // To remove all pending notifications which are not delivered yet but scheduled.

如果您想删除单个或多个特定通知,可以通过以下方法实现。

center.removeDeliveredNotifications(withIdentifiers: ["your notification identifier"])

希望能帮助到你..!!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何清除应用程序中的远程通知? 的相关文章

随机推荐