nativescript-local-notifications icon indicating copy to clipboard operation
nativescript-local-notifications copied to clipboard

clear badge number

Open edyrkaj opened this issue 6 years ago • 7 comments

Exists any possibility to clear badge number after clicking the notification?

edyrkaj avatar Nov 14 '18 17:11 edyrkaj

On iOS?

EddyVerbruggen avatar Nov 16 '18 10:11 EddyVerbruggen

yes @EddyVerbruggen. Thnx

edyrkaj avatar Nov 16 '18 21:11 edyrkaj

I just confirmed with the embedded demo app, the badge is automatically cleared when either launched through the app icon or notification. Is that not working for you (with the demo)?

EddyVerbruggen avatar Nov 17 '18 16:11 EddyVerbruggen

@EddyVerbruggen I have the same problem. Badge is cleared only when app is launched by tapping app icon. After tapping notification badge remains.

Platform: iOS TNS version: 5.2.5 nativescript-local-notifications version: 3.1.2

My code:

` public emit(notification: INotification): void {

    const id = Math.floor(Math.random() * 1000000);
    LocalNotifications.schedule([{
        id: id,
        title: notification.title,
        body: notification.body,
        color: new Color('#0050a0'),
        forceShowWhenInForeground: true,
        badge: notification.badge,
        sound: notification.sound ? 'default' : null
      }]).then(() => {
          console.log('notification scheduling success!');
      }).catch(() => {
          console.log('notification scheduling error!');
      });

    LocalNotifications.addOnMessageReceivedCallback((data: ReceivedNotification) => {
        if (!this.routerExtensions.router.isActive(notification.redirectPath, true)) {
            this.routerExtensions.navigate([notification.redirectPath], {
                transition: {
                    name: 'fade'
                }
            });
            LocalNotifications.cancel(data.id);
        } else {
            LocalNotifications.cancel(data.id);
        }
    }).then(() => {
        console.log('notification received callback success!');
    }).catch(() => {
        console.log('notification received callback error!');
    });
    LocalNotifications.addOnMessageClearedCallback((data: ReceivedNotification) => {
        LocalNotifications.cancel(data.id);
    }).then(() => {
        console.log('notification cleared callback success!');
    }).catch(() => {
        console.log('notification cleared callback error!');
    });
}`

slaven3kopic avatar May 03 '19 06:05 slaven3kopic

Hi, I have the same issue. I tap the app icon but the badge remains. And if I tap again second time and launch the app, then the badge disappears. Is there a solution for this. Appreciate any help

szgozcan avatar Oct 21 '19 19:10 szgozcan

Moreover, when I tap the icon when there is not any notification, the badge appears . In order to clear it, user has to launch and close the app. I have this issue on IOS. I haven't tested in Android. Thx in advance.

szgozcan avatar Oct 22 '19 07:10 szgozcan

I just added UIApplication.sharedApplication.applicationIconBadgeNumber = 0; just incase anyone else has a problem.

lukesUbuntu avatar May 03 '20 04:05 lukesUbuntu