gpt4 book ai didi

ios - 如何删除通知角标(Badge)-Flutter

转载 作者:行者123 更新时间:2023-12-03 08:11:15 25 4
gpt4 key购买 nike

我有 flutter 应用程序,我在其中使用推送通知

当我收到新通知时,我会删除所有通知和角标(Badge),但有时打开应用程序时通知角标(Badge)不会删除,并且会不断增加

这是我找到的删除角标(Badge)的解决方案:-

Ios->appDelegete.swift

import UIKit
import Flutter
import Firebase
import UserNotifications

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)

if #available(iOS 10.0, *) {
application.applicationIconBadgeNumber = 0 // For Clear Badge Counts
let center = UNUserNotificationCenter.current()
center.removeAllDeliveredNotifications()
center.removeAllPendingNotificationRequests()
center.delegate = self as? UNUserNotificationCenterDelegate
}

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}

但它不会删除我的角标(Badge)有什么方法可以删除通知角标(Badge)吗?

最佳答案

尝试在didFinishLaunchingWithOptions之后在AppDelegate.swift中添加以下代码

override func applicationDidEnterBackground(_ application: UIApplication){
application.applicationIconBadgeNumber = 0
}

希望它对你有用

关于ios - 如何删除通知角标(Badge)-Flutter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70751713/

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