[英]how to remove notification badge -Flutter
我有 flutter 应用程序,我在其中使用推送通知
当我收到新通知时,我会删除所有通知和徽章,但有时在打开应用程序时通知徽章不会删除并且它会不断增加
这是我发现删除徽章的解决方案:-
ios->appDelete.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)
}
}
但它不会删除我的徽章有没有办法删除通知徽章?
尝试在didFinishLaunchingWithOptions
之后在AppDelegate.swift
中添加以下代码
override func applicationDidEnterBackground(_ application: UIApplication){
application.applicationIconBadgeNumber = 0
}
希望它对你有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.