我有 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/