How to remove push notification from the notification center?

Greetings everyone,

I’ve implemented GameThrive for our new game to send bonus credits to our players whenever we like. It worked fine but there is a problem that I’m unable to see any solution out there.

I send out the notification, and the user accepts it and gets his/her bonus credits. Now, I expect the notification to disappear but it stays in the Notification Center as long as “the player” removes it manually. I don’t want this because it would lead to people abusing that bug and taking thousands of credits which will lead to messing up with leaderboard indirectly.

I have seen in the documentation that there is a way to remove local notifications with system.cancelNotification() but I haven’t seen a way to remove push notifications from the Notification Center.

Any help would be much appreciated.

Thank you all.

I’m not 100% sure of this, but I would imagine that we don’t have any control over this once the push notification has been received by Notification Center. And I believe system.cancelNotification() removes any scheduled notifications from appearing, I’m not sure it removes existing notifications from notification center. 

If you have the facility to do it, I would tag each push message with some kind of unique identifier which you track on a server. When the user wants to redeems the bonus by accepting the push, your app contacts the server to check the identifier is valid. If it is, you remove that tracked identifier from your server and give them the bonus. If they then try to get the bonus again, the server check will fail and they get no bonus.

It’s a lot more work, but it might be the only way for you to get it to work. A less secure method would be to save the identifier to a local json file or something, and perform the same process as above but only locally.

I always thought developers didn’t need to be directly involved with the Notification Center as the OS cleans it out like WhatsApp notifications when you check the messages but it turns out I was wrong. We should have some power over it, the easier way. Maybe I should do something with the notification badges but I’m not so sure how it will work out or I shall try your method :slight_smile:

I will try out your way in the morning but I’m still open to suggestions. Anyone?

GameThrive dev here. This shouldn’t happen – the notifications should get cleared when the user runs the app.

We’ll investigate this as soon as we can. Could you let me know the model and OS version of your device?

Hello George, this is Serkan here :slight_smile: Sorry to take your time with that problem from both e-mail and there but I managed to find a solution to it. I didn’t really tested out line by line so I’m not pretty sure what part of the code made it work right :slight_smile:

I can only give you that detail, I wasn’t using badge numbers at first so I didn’t send out a notification with a badge but right now I’m using badges and sending out notifications, increasing the badge number by 1 every time and then decrease it in the code.

Hey Serkan. Thanks for the update! Good to know. We’ll double check to make sure this fixes the issue and update our documentation.

I’m not 100% sure of this, but I would imagine that we don’t have any control over this once the push notification has been received by Notification Center. And I believe system.cancelNotification() removes any scheduled notifications from appearing, I’m not sure it removes existing notifications from notification center. 

If you have the facility to do it, I would tag each push message with some kind of unique identifier which you track on a server. When the user wants to redeems the bonus by accepting the push, your app contacts the server to check the identifier is valid. If it is, you remove that tracked identifier from your server and give them the bonus. If they then try to get the bonus again, the server check will fail and they get no bonus.

It’s a lot more work, but it might be the only way for you to get it to work. A less secure method would be to save the identifier to a local json file or something, and perform the same process as above but only locally.

I always thought developers didn’t need to be directly involved with the Notification Center as the OS cleans it out like WhatsApp notifications when you check the messages but it turns out I was wrong. We should have some power over it, the easier way. Maybe I should do something with the notification badges but I’m not so sure how it will work out or I shall try your method :slight_smile:

I will try out your way in the morning but I’m still open to suggestions. Anyone?

GameThrive dev here. This shouldn’t happen – the notifications should get cleared when the user runs the app.

We’ll investigate this as soon as we can. Could you let me know the model and OS version of your device?

Hello George, this is Serkan here :slight_smile: Sorry to take your time with that problem from both e-mail and there but I managed to find a solution to it. I didn’t really tested out line by line so I’m not pretty sure what part of the code made it work right :slight_smile:

I can only give you that detail, I wasn’t using badge numbers at first so I didn’t send out a notification with a badge but right now I’m using badges and sending out notifications, increasing the badge number by 1 every time and then decrease it in the code.

Hey Serkan. Thanks for the update! Good to know. We’ll double check to make sure this fixes the issue and update our documentation.

Hi,

is there an update on  this

Hi @hbspatil,

I’ve marked this solved after I saw your post. I’ve solved the problem by increasing/decreasing badge numbers. Hope this helps.

Quoting myself:

I can only give you that detail, I wasn’t using badge numbers at first so I didn’t send out a notification with a badge but right now I’m using badges and sending out notifications, increasing the badge number by 1 every time and then decrease it in the code.

Yep, bgmadclown has the right solution. In iOS, to be able to remove notifications, you need to set the badge count to at least 1. Then you can either send another notification with badge count 0, or call the following methods in the app:

native.setProperty( “applicationIconBadgeNumber”, 0 )

system.cancelNotification()

Hi,

is there an update on  this

Hi @hbspatil,

I’ve marked this solved after I saw your post. I’ve solved the problem by increasing/decreasing badge numbers. Hope this helps.

Quoting myself:

I can only give you that detail, I wasn’t using badge numbers at first so I didn’t send out a notification with a badge but right now I’m using badges and sending out notifications, increasing the badge number by 1 every time and then decrease it in the code.

Yep, bgmadclown has the right solution. In iOS, to be able to remove notifications, you need to set the badge count to at least 1. Then you can either send another notification with badge count 0, or call the following methods in the app:

native.setProperty( “applicationIconBadgeNumber”, 0 )

system.cancelNotification()