从firebase覆盖iOS badgenumber

发布于 2025-01-21 11:57:55 字数 912 浏览 0 评论 0原文

我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文