【问题标题】:Ionic 4 FCM.onNotification not called on iOS if app is killed如果应用程序被杀死,则不会在 iOS 上调用 Ionic 4 FCM.onNotification
【发布时间】:2020-03-14 23:45:37
【问题描述】:

我已经为 iOS 上的 FCM 推送通知问题苦苦挣扎了数周。问题是,如果单击通知时应用程序处于终止状态,则不会触发 fcm.onNotification 回调。 检查案例:

  • iOS - 前台应用程序 - 未显示通知弹出窗口,正在运行正确的代码:OK
  • iOS - 应用程序在后台运行 - 显示通知弹出窗口 - 单击通知 - 正在运行正确的代码:OK
  • iOS - 应用程序被操作系统杀死/手动滑走 - 显示通知弹出窗口 - 单击通知 - 应用程序打开 - platform.ready 正确运行 - onNotification 未触发。

在安卓上一切正常。

我已经尝试在通知中设置所有我可以用谷歌搜索的内容:

  • 强制启动:“1”
  • content_available:真
  • 优先级:“高”
  • click_action:“FCM_PLUGIN_ACTIVITY”

应该运行的代码:

this.platform.ready().then(() => {
    alert("This alert is shown");
    this.fcm.onNotification().subscribe(data => {
        alert("This alert is not shown");
        if (data.wasTapped) {
            alert('Received in background');
            self.router.navigate([data.landing_page, data.content]);
        } else {
            alert('Received in foreground');
            self.router.navigate([data.landing_page, data.content]);
        }
    });     
});

谢谢!

【问题讨论】:

    标签: ionic-framework firebase-cloud-messaging ionic4


    【解决方案1】:

    我使 iOS 后台通知与在 aps 有效负载中设置的 content-available: 1 一起工作,并在服务中测试 additionalData.foreground 的值是否为 false。

    【讨论】:

    • :先生,您能告诉我如何设置aps有效载荷和additionalData.foreground值吗?
    • @Kapilsoni 请发布一个新问题,您可以在新问题下方的评论中引用我。这里没有足够的信息来回答你。
    • 我已经在以下链接发布了新问题检查:stackoverflow.com/questions/62410530/…
    • 发表了答案。
    • content-available:1 你的答案?
    猜你喜欢
    • 1970-01-01
    • 2019-08-19
    • 2021-07-29
    • 2021-03-02
    • 1970-01-01
    • 2015-05-15
    • 1970-01-01
    • 1970-01-01
    • 2018-10-01
    相关资源
    最近更新 更多