从firebase覆盖iOS badgenumber
我的iOS应用程序有firebase,因为从堆栈溢出来看,我已经很明显iOS上的firebase +1徽章编号为我。相反,我必须自己从AppDelegate内部进行自己的计算。
但是,我放下了以下的代码,希望它会覆盖通过Firebase发送的任何徽章号码,但它们似乎没有效果。
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userDefault: UserDefaults = UserDefaults()
if var badgeCount = userDefault.value(forKey: "badgeCount") as? Int {
badgeCount += 1
UserDefaults.standard.setValue(badgeCount, forKey: "badgeCount")
UIApplication.shared.applicationIconBadgeNumber = badgeCount
}
}
作为进一步的测试,我什至尝试将以下函数的以下线编码为上面的函数,看看它是否会覆盖Firebase发送的徽章编号:
UIApplication.shared.applicationIconBadgeNumber = 48
事实证明,它根本不会覆盖通过Firebase发送的徽章编号,我通过火箱发送的数字“ 88”将在收到推送通知后成为新的徽章编号,而“ 48”不会被覆盖。
有人有任何线索我做错了什么吗?
谢谢!
I have Firebase for my iOS app and as it is already clear from Stack Overflow that I cannot have Firebase +1 badge number on iOS for me. Instead I have to do my own calculation from within appdelegate myself.
However, I have put down below codes expecting that it will override whatever badge number sent in through Firebase, but they seem to have no effect.
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userDefault: UserDefaults = UserDefaults()
if var badgeCount = userDefault.value(forKey: "badgeCount") as? Int {
badgeCount += 1
UserDefaults.standard.setValue(badgeCount, forKey: "badgeCount")
UIApplication.shared.applicationIconBadgeNumber = badgeCount
}
}
As a further test, I have even tried to hardcode the below line to the function above and see if it will override the badge number sent in by Firebase:
UIApplication.shared.applicationIconBadgeNumber = 48
And it turns out it will not override the badge number sent through Firebase at all, the number '88' I sent through Firebase will become the new badge number upon receiving the push notification and it will not be overridden with '48'.
Do anyone have any clues what I have done wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论