I'd like to better control what notifications are being displayed to my users and selectively silence some of them. In order to do this I have implemented a UNNotificationServiceExtension
in my app, which allows me to intercept and modify notifications even when my app is not running. The problem however is that even if I don't call didReceive(_:withContentHandler:)
the system will still display the remote notification after approximately 30 seconds. How can I prevent this from happening?
Remote Notifications are notifications sent to a mobile device using a data-channel from a service provider in real-time.
Go to Settings and tap Notifications. Select an app under Notification Style. Under Alerts, choose the alert style that you want. If you turn on Allow Notifications, choose when you want the notifications delivered — immediately or in the scheduled notification summary.
Just clear "Automatically manage signing" checkbox and select it again, you will find the "push notification capability" or other capability in Capabilities page.
As of iOS 11, it is not possible to suppress push notifications from being displayed using a UNNotificationServiceExtension
.
In WWDC 17's Best Practices and What’s New in User Notifications, Teja states explicitly that such a thing cannot be done (starting at 22:17 min):
All work should be either about modifying or enhancing this notification. The service extension also doesn't have the power to drop this notification or prevent it from being displayed. This notification will get delivered to the device. If instead you want to launch your application in the background and run some additional processing, you should send a silent notification. You can also send a silent notification and launch your app in the background and your app can determine whether or not to schedule a local notification if you want to present a conditional notification.
From iOS 13.3 the notification service entitlement com.apple.developer.usernotifications.filtering allows for filtering notifications (as pointed out in Aviharsh Shukla's comment).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With