本文介绍了是否可以防止显示远程通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更好地控制向我的用户显示哪些通知,并有选择地将其中一些通知静音.为了做到这一点,我在我的应用程序中实现了一个 UNNotificationServiceExtension应用程序,即使我的应用程序未运行,它也允许我拦截和修改通知.然而,问题是即使我不调用 didReceive(_:withContentHandler:) 系统仍然会在大约 30 秒后显示远程通知.我怎样才能防止这种情况发生?

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?

推荐答案

iOS 11 起,无法使用 UNNotificationServiceExtension 抑制显示推送通知.

As of iOS 11, it is not possible to suppress push notifications from being displayed using a UNNotificationServiceExtension.

在 WWDC 17 的 Best Practices以及用户通知中的新增功能,Teja 明确表示无法执行此类操作(从 22:17 分钟开始):

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

所有工作都应该与修改或增强此通知有关.服务扩展也无权删除此通知或阻止其显示.此通知将发送到设备.相反,如果您想在后台启动您的应用程序并运行一些额外的处理,您应该发送一个静默通知.您还可以发送静默通知并在后台启动您的应用,如果您想显示条件通知,您的应用可以决定是否安排本地通知.

来自 iOS 13.3 通知服务权利 com.apple.developer.usernotifications.filtering 允许过滤通知(如 Aviharsh Shukla 的评论中指出的那样).

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

这篇关于是否可以防止显示远程通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 03:32
查看更多