1

I want to send all users of my app a Push Notification that will bring them to a certain page in the app.

However, I only want one user to be able to tap it and go to the page, and when one user loads the page that the push brings them into, I want to silently remove the push from all other users.

Is this possible to do? I'm not sure how to grab all sent push notifications, whereas the UNUserNotificationCenter only grabs pushes sent on that device.

Thank you in advance!

picciano
  • 22,341
  • 9
  • 69
  • 82
Logan
  • 1,172
  • 9
  • 23
  • 1
    what if few users tap notification same time? – canister_exister Apr 10 '19 at 20:49
  • That's fine - I just want to remove all notifications after the first user loads the page that it brings you into – Logan Apr 10 '19 at 21:15
  • 2
    Send a notification that contains a url. The url will then hit an endpoint and return a deep link for the app. But only for the first person to get there. Subsequent users get a deep link that says “sorry you were too slow” or something. – Fogmeister Apr 10 '19 at 22:03
  • @Fogmeister This is what I currently do, but it's less than ideal. I'd rather not have every user besides the first receive an error, I just don't want them to know anything about it – Logan Apr 11 '19 at 18:44
  • @Logan who said anything about errors? Make it not an error. If you send someone a notification it’s because you want them to know about it. Saying “I want to send all users notifications” and “I don’t want them to know about it” is not a thing you can do. It is a contradiction. – Fogmeister Apr 11 '19 at 19:37
  • @Logan how annoyed would you be if you received a notification on your phone and then it disappeared just before you pressed it? Or wasn’t there at all when you tried to look at it. That would cause me to very quickly delete your app. – Fogmeister Apr 11 '19 at 19:38

4 Answers4

1

I believe that this is possible if you use silent notifications.

  1. Send a silent notification of type A.
  2. All devices receive a type A notification and create local notifications in their UI.
  3. A user press this local notification and load the page from the server.
  4. Application of that use on the click / load event will send some request/event to your server that someone access the link.
  5. Your server will send another silent notification of type B.
  6. All devices receive the type B notification and use the code of the links to discard the type A notification from their own notification center.

Here are relevant posts of clearing notifications:

Possible problems / Issues:

  • Between the user's click step 3 and step 6 it may take some time if you consider the push delivery times, so someone else may press the link. It's not instant. This can become worse in bad network conditions.

  • It may be annoying to the users that get a beep on their devices and the notification at last cleared because someone else was faster.

madlymad
  • 6,367
  • 6
  • 37
  • 68
  • I read through that post and attempted it, but I don't think it's what I'm looking for here. This would just clear all notifications on a specific device, right? I'm not sure how opening the app on one device would access the UNUserNotificationCenter of another device – Logan Apr 11 '19 at 14:59
  • @Logan I re-write my idea, I hope that now it's more clear. With that code you clear the notifications of your app. I also find some code to clear one notification. You don't actually run the clear on all devices directly this is not possible, this will perform via your server's involvement and the second push. – madlymad Apr 11 '19 at 17:10
  • thank you! I will give this a shot, I appreciate the detailed write-up – Logan Apr 11 '19 at 18:44
0

You cannot remove a push notification once it has been sent.

Although you could update the App badging by sending another push to reset the badging to zero. While this won't remove the previous push message, it can hide the red badging on the App icon.

picciano
  • 22,341
  • 9
  • 69
  • 82
0

You can simply remove the notification by

Sending the badge count as 0

APNS payload will be :

{
    "aps" : {
        "alert" : "",
        "badge" : 0,
        "sound" : "bingbong.aiff"
    }
}
Razi Tiwana
  • 1,425
  • 2
  • 13
  • 16
  • Doesn't this just deal with the badge that shows up on the home page of the device? – Logan Apr 11 '19 at 14:35
  • @Logan This removes all the notification that are sent before, This results in exactly what your use case is. This is what big app use to remove the Notification is the user has read it on some other device. This is the best way as this doent even require your app to be running as this is handles by iOS. – Razi Tiwana Apr 11 '19 at 17:40
0

If you want to remove or decrease badge count number then you can do it easily with

UIApplication.shared.applicationIconBadgeNumber = max(UIApplication.shared.applicationIconBadgeNumber - 1, 0)

If you want to remove a single notification from notification center then, you can do it by using UNUserNotificationCenter in iOS 10 and above.

UNUserNotificationCenter object manage all notification-related behaviors in app or app extension.

You can removes the specified notification requests from Notification Center by using :

func removeDeliveredNotifications(withIdentifiers: [String])
Rocky
  • 2,903
  • 1
  • 22
  • 26