这可能是一个问题,但我想知道要使用什么而不是UILocalNotification
iOS10.我正在开发一个部署目标为iOS8的应用程序,所以可以使用UILocalNotification
吗?
我UserNotification
在我的应用程序中使用框架并发送本地通知(不是推送通知),我想将徽章设置为收到的通知数量,所以我所做的是将收到的通知数量设置为用户默认值然后我尝试将值分配给徽章以获取徽章编号,但徽章编号不会增加.这是我的代码
设置接收通知的值
center.getDeliveredNotifications { notification in
UserDefaults.standard.set(notification.count, forKey: Constants.NOTIFICATION_COUNT)
print("notification.count \(notification.count)")
print(".count noti \(UserDefaults.standard.integer(forKey: Constants.NOTIFICATION_COUNT))")
}
Run Code Online (Sandbox Code Playgroud)
这准确地打印了收到的通知数量,当我决定将其设置为我的徽章时,它只显示1
content.badge = NSNumber(value: UserDefaults.standard.integer(forKey: Constants.NOTIFICATION_COUNT))
Run Code Online (Sandbox Code Playgroud)
我不知道为什么价值不会每次都增加.任何帮助,将不胜感激.
或者,如果可以随时在应用程序中的任何位置更新徽章.