EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 448 forks source link

Notifications' Badge number randomly stuck and left unchanged on iOS #1674

Open deindesignpl opened 3 years ago

deindesignpl commented 3 years ago

Hello, firstly thank you for a great plugin. It helps our team a lot.

I use latest version of the plugin so 10.5.2. I currently try to deal with one inconsistency in iOS messaging. At some point some of our users get some notifications however badge number doesn't reset. autoClearBadge is set to true (by default actually).

I tried to enforce clearing badge count it by resetting it in exactly same way like it's done in messaging.ios.js. Straight after call to registerForPushNotifications(), so I made quickly and called following resetBadgeCount() function:

import * as application from 'tns-core-modules/application';

const resetBadgeCount = () => {
    const app = UIApplication.sharedApplication;

    if (!app) {
        application.on(application.launchEvent, resetBadgeCount);

        return;
    }

    // Reset badge number
    if (app.applicationState === 0) {
        app.applicationIconBadgeNumber = 0;
    }
};

However it seem to still keep the badge count number not reset. I suspect it might be something with applicationState in messaging.ios.js. The problem is only on iOS. There are no exact steps to reproduce the issue.

nicmanzini commented 3 years ago

maybe don't check for applicationState === 0 and also app.applicationIconBadgeNumber must be called on the main thread.

deindesignpl commented 3 years ago

Thank you for the message. Actually, that's how it currently is specified within the plugin (messaging.ios.js file). I'm going to try without applicationState, and let you know whether that solves issues. If it does, I think we may need to review that part of plugin as it seems to leave some users with notification badge hanging

johandrott commented 2 years ago

Any update on this? I'm currently having the same issue with the badge not being cleared.