swift - 本地通知中的徽章
问题描述
当我注册新通知时 - UIApplication.shared.applicationIconBadgeNumber - 总是 0,这就是为什么我的徽章中总是“1”。如何在本地通知中更新它?
let content = UNMutableNotificationContent()
let notificationInterval = components(forDay: settings.object.timeInterval)
let requestIdentifier = settings.object.identifier
content.badge = Swift.min(notificationsCount, UIApplication.shared.applicationIconBadgeNumber + 1) as NSNumber
content.body = settings.object.body
content.title = settings.object.title
content.categoryIdentifier = "categoryIdentifier"
content.sound = UNNotificationSound.default()
content.setValue(true, forKey: "shouldAlwaysAlertWhileAppIsForeground")
let trigger = UNCalendarNotificationTrigger(dateMatching: notificationInterval, repeats: true)
let request = UNNotificationRequest(identifier: requestIdentifier, content: content, trigger: trigger)
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [request.identifier])
UNUserNotificationCenter.current().add(request) { error in
if error != nil {
print(error?.localizedDescription ?? "Notification error")
}
print("Notification Register Success")
}
解决方案
推荐阅读
- node.js - 问题从反应发送请求到虚拟盒 Ubuntu 18.04 中的节点
- python - 如何更改 seaborn.displot 图形的字体大小?
- ios - 如何呈现作为 mapView 委托的视图控制器,嵌入在 tabBar 控制器中?
- python - 在python中跟踪子类的装饰方法
- android - SharedPreferences 将数据保存到对象列表的问题
- javascript - 错误类型错误:无法读取 null 的属性“盐”
- postgresql - 在 SQL Server 和 PostgreSQL 中将本地日期时间值转换为 UTC 日期时间值
- rsync - 使用 rsync 将文件迁移到新服务器的问题
- spring-boot - StackOverflow 上保存具有双向 ManyToMany 属性的实体
- java - Android 中的 Message.obtain()