Issue with Suppressing Push Notifications Using UNNotificationServiceExtension

Hello,

I have developed an update for my app where I handle push notifications (from APNs or FCM) and manage different notification categories using checks, storing the values in UserDefaults. So far, everything works fine, and the logs correctly indicate the state of each category when a notification is received.

The issue arises when handling notifications in three states: foreground, background, and terminated (killed). I am using UNNotificationServiceExtension and in the didReceive method, I check the state of the notification. Depending on whether the state is true or false, I want the notification to be shown or not to the user. However, despite my efforts, the alert/notification part of the payload always ends up being displayed.

Additionally, I have disabled serviceExtensionTimeWillExpire as it was being triggered, but still, after a few seconds, the notification ends up appearing.

I have configured everything correctly, including mutable content, notification handling, etc. How can I prevent these notifications from being shown to the user when needed?

Thank you for your assistance!

Have you applied for and been approved to use the com.apple.developer.usernotifications.filtering entitlement?

Without it, you will not be able to suppress the visibility of notifications.

If you do have this entitlement, there can be a number of reasons this is failing:

  • your entitlements and/or provisioning profiles are not configured correctly
  • your extension is either not launching at all for some reason, or crashing at launch
  • you are going over the memory or time limits, and your extension is being terminated by the system. If serviceExtensionTimeWillExpire was being triggered, then disabling it will only result in your extension being terminated. This indicates that the extension is taking too long, or there is a bug in your code.

What you would want to do first is, after confirming that you do have the above entitlement, and it has been correctly configured in your project, to determine if your extension is being launched at all, crashing right away, or in a few seconds perhaps like you say, or going over the time or memory limits.

Then you can find a solution to correct the problem that is causing those failures.


Argun Tekant /  DTS Engineer / Core Technologies

Hello,

Thank you very much for your response. I wasn't aware of com.apple.developer.usernotifications.filtering. I have now looked into it and requested its usage. Currently, I'm awaiting approval.

I will inform you once there are any updates.

Issue with Suppressing Push Notifications Using UNNotificationServiceExtension
 
 
Q