gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 05:20:38 25 4
gpt4 key购买 nike

从 iPhone 屏幕顶部向下滑动时,是否可以清除通知横幅中的远程通知。我尝试将角标(Badge)编号设置为零:

application.applicationIconBadgeNumber = 0 

在委托(delegate) didFinishLaunchingWithOptionsdidReceiveRemoteNotification 中,但它没有清除通知。谢谢。

最佳答案

在 iOS 10 中,上述所有解决方案都已弃用

'cancelAllLocalNotifications()' was deprecated in iOS 10.0: Use UserNotifications Framework's -[UNUserNotificationCenter removeAllPendingNotificationRequests]

使用下面的代码取消通知并重置角标(Badge)计数

对于 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"])

希望对您有所帮助..!

关于ios - 如何清除应用中的远程通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30364315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com