使用 phonegap-plugin-push 与 FCM 通知:如何正确设置 content-available:1。

问题描述 投票:2回答:1

是否 content-available 是否必须是push数据对象的第一级子对象,才能通过phonegap-plugin-push触发通知事件处理程序?

如果是这样的话,有什么方法可以设置 content-available: 1 作为firebase控制台通知中推送数据对象的第一级子对象?


我用cordova CLI创建了一个使用phonegap-plugin-push的android应用,我使用Google Firebase控制台来发送推送通知。

当应用程序在前台时,推送通知的工作与预期一样。如果当推送通知到达时,应用程序不在前台(例如,通过点击锁屏上的通知打开应用程序),通知事件处理程序从未被调用。

我相信,问题的原因是由于 content-available: 1 境内 additionalData 对象。

在firebase控制台中,我看到的唯一一个输入 content-available 是在 "自定义数据 "字段中。

这是应用程序处于前台时接收到的推送数据对象,并且 content-available 设置为 1 in Firebase console > notifications > advanced options > custom data.

data {
  title: "message title", 
  message: "test message 12", 
  additionalData: {
    content-available: "1", 
    coldstart: false, 
    collapse_key: "com.domain.appname", 
    foreground: true
    }
  }
cordova notifications firebase-cloud-messaging phonegap-pushplugin
1个回答
0
投票

这是我发送给Google API的有效载荷。当应用处于前台、后台或应用关闭时,这都会起作用。这在Android和IOS中有效。

{ 
"registration_ids":["device token"],
"content_available": true,
"notification" : {
    "force-start": "1",
    "content-available": "1",
    "no-cache": "1",
    "body":"Test" ,
    "title" : "Test",
    "sound" : "default" ,
    "icon":"default",
    "badge": 56
},
"data": {
    "force-start": "1",
    "content-available": "1",
    "no-cache": "1",
    "body":"Test" ,
    "title" : "Test",
    "sound" : "default" ,
    "icon":"default",
    "badge": 56
},
"priority":10

}

© www.soinside.com 2019 - 2024. All rights reserved.