Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
341 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...