0

As of iOS 16 is there a bulletproof way to remove an already delivered apns push notification?

In the past people have been trying to partially achieve it using notification extensions and background modes, but to the best of my understanding those all fail if the app is in state killed by user.

The use case is this: I have an iPad and and iPhone and I recieve the same message on both via remote push. I read the message on the iPad and acknowledge it. Now the same message is still present on the lockscreen of iPhone. This already ready message should now be removed because it is unnecessarily distracting.

user1195883
  • 654
  • 4
  • 19

1 Answers1

0

If you wanted it to disappear from the other device immediately you'd need to send a (silent) push notification out to let other devices know to cancel the notification via an identifier. Otherwise, background modes should work even if the app is in a killed state, because the OS will periodically bring the app in the background to fetch data — but that won't be immediate.

This answer explains how to remove a specific notification.

shim
  • 9,289
  • 12
  • 69
  • 108
  • You mean sending a `"content-available" : 1` message that contains some custom id attribute and then find and remove the message in `application(_:didReceiveRemoteNotification:fetchCompletionHandler:)`? The problem with this approach as far as I know is that those messages are throttled by Apple and are not delivered reliably (that's why I mentioned "bulletproof"). – user1195883 Jun 16 '23 at 14:55
  • If you want to use APNS then you're pretty much at the mercy of the OS either way. – shim Jun 16 '23 at 15:23
  • What some apps do is they don't send push notifications out to all devices simultaneously, but rather they send one out to, for example, the currently active device, and if the content hasn't been viewed within a certain time, then notifications to other devices are sent. Slack does something like this. – shim Jun 16 '23 at 15:25
  • One is at the mercy of the OS when using iOS in general I would say, and that's kind of obvious :) I'll try to investigate how Skype does it because as far as I know they instantly remove push messages on the iOS devices as soon as you've read the message on the desktop version. – user1195883 Jun 17 '23 at 10:45