【问题标题】:Can handler not show remote notification when iOS app is killed?iOS应用程序被杀死时处理程序不能显示远程通知吗?
【发布时间】:2020-01-14 15:31:37
【问题描述】:

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

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? 上面说苹果不允许这样做,对吗?

【问题讨论】:

    标签: ios xcode apple-push-notifications unnotificationserviceextension


    【解决方案1】:

    是的,没错。

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

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

    【讨论】:

      【解决方案2】:

      您是否尝试完全删除通知? (前景和背景?) 如果是这种情况,那么您应该要求您的后端服务向您发送静默通知而不是正常通知。你不应该自己处理。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-20
        • 1970-01-01
        • 2023-04-02
        • 2017-06-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多