swift – Override iOS BadgeNumber from Firebase

[ad_1]

I’ve Firebase for my iOS app and as it’s already clear from stackoverflow that I can not have Firebase +1 badge quantity on iOS for me. As a substitute I’ve to do my very own calculation from inside appdelegate myself.

Nonetheless, I’ve put down beneath codes anticipating that it’s going to override no matter badge quantity despatched in by means of Firebase, however they appear to have no impact.

func userNotificationCenter(_ heart: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    let userDefault: UserDefaults = UserDefaults()
    if var badgeCount = userDefault.worth(forKey: "badgeCount") as? Int {
        badgeCount += 1
        UserDefaults.normal.setValue(badgeCount, forKey: "badgeCount")
        UIApplication.shared.applicationIconBadgeNumber = badgeCount
    }
}

As an additional check, I’ve even tried to hardcode the beneath line to the perform above and see if it is going to override the badge quantity despatched in by Firebase:

UIApplication.shared.applicationIconBadgeNumber = 48

And it seems it won’t override the badge quantity despatched by means of Firebase in any respect, the quantity ’88’ I despatched by means of Firebase will turn out to be the brand new badge quantity upon receiving the push notification and it’ll not be overridden with ’48’.

Do anybody have any clues what I’ve performed incorrect?

Thanks!

[ad_2]

Leave a Reply