iosswiftapple-push-notificationsunnotificationserviceextension

Hide notifications received through NotificationService Extension


I'm using the NotificationService Extension target to be able to modify push notifications before they are presented. It's working well but there is some notifications that I would like to not present to the user after they have been processed.

I'v tried to set the bestAttemptContent title and body to "" but it return the full notification.

I've also tried setting the aps["content-available"] to 1 and the body to "" but I get the same effect.


Solution

  • The Situation

    I actually tried to achieve the same thing as you, managing what kind of notifications get delivered to a specific device using the notification service extension locally. However, I had to figure out it's by design that...

    This is because Apple doesn't want you to spam a user's phone with notifications (even or especially when processed in the background and not even delivered), given this could drain battery life e. g.

    The Solution

    You have four possible choices on what to do now: