1

THE SITUATION:

I need to send push notifications to a certain group of user.
When the first user of this group perform a certain action (click on the button inside the notification), I need to remove the notification from all the other users' devices.

NOTES:

I am using Quasar as hybrid framework and Laravel for server API. I use oneSignal to send push notifications with php cURL requests.

As device OS I am focusing now on Android, but ideally I am looking for a way to achieve this in both Android and IOS.

ATTEMPTS:

At the moment I send the notification with the notification_id as a payload. When the user click on the button, it trigger a callback that send the notification_id back to server. Until here no problem.

I have the id of the notification that need to be removed from the other devices.

But now I don't know how to remove it, from the server.

OneSignal has a cancel method, but it applies only for scheduled notifications (not sent). If I try to apply that method to a sent notification it gives the error: Notification has already been sent to all recipients.

THE QUESTION:

Is it possible to remove a push notification, from the server, after it has been sent?
If not, what do you suggest as an alternative to implement that behavior?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
FrancescoMussi
  • 20,760
  • 39
  • 126
  • 178
  • I'm not familiar with "oneSignal" but if it's possible to send `custom` field you can use user callback on notification click, handle at server side and send push with (let's say) `close` tag and in `FirebaseMessagingService` just remove notification with `NotificationManager.clearAll()` – Stanislav Bondar Dec 17 '18 at 14:39
  • Thanks for reply! I send the notification_id as a payload along with the notification itself. I have a callback implemented when the user click on the button. But I don't how to remove the notifications from the server. OneSignal has a cancel method: https://documentation.onesignal.com/reference#cancel-notification -, but it applies only to scheduled notifcations (not already been sent). – FrancescoMussi Dec 17 '18 at 14:43

1 Answers1

2

Hey Please check these Steps Maybe it will help you for iOS.

Scenario

-A server will send a notification to a certain group of user

-The first User will tap on Notification Try after that just inform to the server with API call for notification ID. (you can put the logic in server side for if user informing you first time for the notification id you can send a silent notification to all user where the left user who not seen the notification yet, can remove all delivered and pending notification with below line of code).

Just check the Type of notification. if notification is silent and type of notification is For remove notification from another user device, Just write below code in didReciveRemortNotification APP delegate method.

application.applicationIconBadgeNumber = 0
   // For Clear Badge Counts
let center = UNUserNotificationCenter.current()
center.removeAllDeliveredNotifications()
   // To remove all delivered notifications
center.removeAllPendingNotificationRequests()
  // To remove all pending notifications which are not delivered yet but scheduled.
Sumit singh
  • 2,398
  • 1
  • 15
  • 30
  • 1
    Thanks @Sumit. Silent notification is a good suggestion. I see that oneSignal allow them: https://documentation.onesignal.com/docs/silent-notifications I will research on that! – FrancescoMussi Dec 17 '18 at 15:36