EddyVerbruggen / nativescript-local-notifications

:mailbox: NativeScript plugin to easily schedule local notifications
MIT License
162 stars 57 forks source link

clear badge number #122

Open edyrkaj opened 5 years ago

edyrkaj commented 5 years ago

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

EddyVerbruggen commented 5 years ago

On iOS?

edyrkaj commented 5 years ago

yes @EddyVerbruggen. Thnx

EddyVerbruggen commented 5 years ago

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)?

slaven3kopic commented 5 years ago

@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!');
    });
}`
szgozcan commented 5 years ago

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 commented 5 years ago

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.

lukesUbuntu commented 4 years ago

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