是否可以防止显示远程通知? [英] Is it possible to prevent a remote notification from being displayed?

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

问题描述

我想更好地控制向我的用户显示哪些通知,并有选择地使其中一些静音.为此,我在我的应用程序中实现了 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的最佳做法和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):

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

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆