【问题标题】:Which delegate method receive firebase push notification payload in background or terminated state?哪个委托方法在后台或终止状态下接收 Firebase 推送通知有效负载?
【发布时间】:2021-05-18 13:36:30
【问题描述】:

在 willPresent 通知方法中,当应用程序处于前台状态时,我们会收到有效负载。 实际上,我想从 firebase 推送通知响应生成本地通知,但我不明白当应用程序处于后台和终止状态时调用了哪些委托方法。

【问题讨论】:

    标签: swift firebase firebase-cloud-messaging


    【解决方案1】:

    您应该始终调用 willPresent 方法的 completionHandler 方法,正如 docs 中提到的那样:

    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([.banner, .sound])
    }
    

    这样,即使在后台或终止状态下,您也可以处理通知。

    【讨论】:

    • Apple 文档说“询问 willPresent 委托如何处理在应用程序在前台运行时到达的通知。”
    猜你喜欢
    • 1970-01-01
    • 2011-09-01
    • 1970-01-01
    • 2013-01-14
    • 2011-08-28
    • 1970-01-01
    • 2022-08-18
    • 1970-01-01
    • 2020-08-02
    相关资源
    最近更新 更多