ios - 当 iOS 应用程序被终止时,处理程序可以不显示远程通知吗?

标签 ios xcode apple-push-notifications unnotificationserviceextension

我的要求是阻止显示远程通知。
如果应用程序位于前台或后台,我可以通过以下方法处理此问题:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
        //logic hide notification here
    }
public func userNotificationCenter(_ center: UNUserNotificationCenter,
                                       willPresent notification: UNNotification,
                                       withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        //logic hide notification here
    }

当应用程序被终止时,我尝试在 UNNotificationServiceExtension 中处理逻辑,但它不起作用:

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        // logic hide notification here
    }

我读过这篇文章:Is it possible to prevent a remote notification from being displayed? 据说苹果不允许这样做,这是正确的吗?

最佳答案

是的,这是正确的。

您无法捕获远程通知并将其隐藏。不接收远程通知的最佳方法是拒绝该权限。如果您的服务器发送远程通知,您可以将其配置为在您不需要时不发送通知。

发送通知而不显示通知的另一种方法是发送“静默通知”。它允许您接收通知、获取其内容并做您想做的事情(您只有 30 秒)。我认为,您可以发送静默通知、检查内容并在需要时发送本地通知,但我不确定。

关于ios - 当 iOS 应用程序被终止时,处理程序可以不显示远程通知吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59736987/

相关文章:

c# - 上一次Xamarin.iOS更新后SIGABRT错误

iphone - iOS:MFMailComposeViewController 不适用于模型

ios - Xcode 服务器 : No services available 问题

ios - 当应用商店中有新的更新(最新版本)时,需要在我的 iOS 应用程序中显示通知

ios - 将项目从 swift 4 转换为 swift 5 时,类型 'ViewController' 的值错误没有成员 'keyboardDidShow(notification:)'

ios - 识别在iOS的WebView中播放的youtube视频网址?

objective-c - 使用 ASIHTTPRequest

具有泛型和 Xcode 自动完成功能的 Objective-C 方法返回类型

ios - 更改推送通知声音

xcode - 获取生产 APNS token