在我正在处理的应用程序中(iOS 11(,以更新我们使用的徽章号:
UIApplication.shared.applicationIconBadgeNumber = number
该应用程序更新徽章编号,并提供了没有问题的值。
,然后...
推送通知带有"徽章"键,该应用程序以推送通知值更新徽章编号,但是,使用 ApplicationIconBadgenumber 从那里开始所有更新。知道为什么?
您需要在AppDelegate
中实现用户局。
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
在didFinishLaunchingWithOptions
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
if error != nil {
// Your Code
}
}
return true
}
对于徽章更新,您需要使用以下代码
let alert = UNMutableNotificationContent()
alert.badge = 10 //your badge count