Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to prevent a remote notification from being displayed?

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 UNNotificationServiceExtensionin 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?

like image 809
spacitron Avatar asked Apr 19 '17 15:04

spacitron


People also ask

What are remote notifications in Android?

Remote Notifications are notifications sent to a mobile device using a data-channel from a service provider in real-time.

How do I turn on remote notifications on my iPhone?

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.

How do I turn off push notifications in Xcode?

Just clear "Automatically manage signing" checkbox and select it again, you will find the "push notification capability" or other capability in Capabilities page.


1 Answers

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).

like image 109
Landschaft Avatar answered Oct 01 '22 02:10

Landschaft