raix-push icon indicating copy to clipboard operation
raix-push copied to clipboard

Clearing Badge Icons from Client

Open gkrizek opened this issue 7 years ago • 6 comments

Is there a way to clear badge icons from the client?

For example: If someone has the app open while a notification comes in, it doesn't make a sound or show the notification, but it still adds the badge icon to app's icon. Is there a way to clear this from the client without forcing the user to exit the app and reopen it to clear it?

The only way I can see to clear the badge icon without the user's action is to send a new notification with a blank payload and a badge of 0.

gkrizek avatar Nov 14 '16 15:11 gkrizek

@gkrizek I have a similar problem on Android using Firebase. iOS is working fine when I use Push.setBadge(0);

Have you (or anyone else) figured out how to clear on Android?

carpmike avatar Feb 18 '17 15:02 carpmike

I need a similar feature but i think it's possible to set the badge option to 0 to clear badge like on iOS.

'serverNotification'(title, text, userId, badge) {
    Push.send({
      title,
      text,
      from: 'server',
      badge: badge || 0,
      query: { userId },
    });
  },

not tested

Maybe you can set a method called when the user is on your app to clear all badges ?

NoMaxLand avatar Jul 30 '17 16:07 NoMaxLand

@Makss24 I haven't touch my Meteor project in a long time, but If I remember right, I fixed the problem with this function:

 'resetBadge': function(){
    var user = Meteor.userId();
    Meteor.users.update({_id: user}, {$set: {'badge': 0}});
    Push.send({
      from: "",
      title: "",
      text: "",
      badge: 0,
      query: {
        userId: user
      }
    });

Then whenever someone did something that would warrant a badge reset, I called that function from the client. For example, I had a messaging app, so when someone clicked 'Send', that must mean that they say the unread message and the badge isn't needed anymore. (There are exceptions to that so it's not 100%)

  'click #sendbutton': function(){
    Meteor.call('resetBadge');
     ...

Source: https://github.com/gkrizek/ghostwall/

gkrizek avatar Jul 30 '17 16:07 gkrizek

Great !

I'm beginning in push notification world and I don't use badges feature yet. But I understand that you set count badge in the database ? Raix:push doesn't manage it ?

Secondly, when you send a notification with a title and a text empty, it's not sending to user if app is closed ? edit: Apparently, the answer to my second asking is no. I just tried.

NoMaxLand avatar Jul 30 '17 16:07 NoMaxLand

I don't know if we can use phonegap-plugin-push native functions, otherwise, clear notifications must be right with https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/API.md#pushclearallnotificationssuccesshandler-errorhandler---ios--android-only

But thanks you for your answer. It's will be easier.

NoMaxLand avatar Jul 30 '17 16:07 NoMaxLand

Hello Guys, please help me out with one issue, is it possible to set badge for android using this package or I need to use some other npm. Thanks in advance.

rashmimhatre100 avatar Sep 18 '18 09:09 rashmimhatre100