Firebase云消息传递-iOS徽章

Firebase云消息传递-iOS徽章,ios,firebase,firebase-cloud-messaging,Ios,Firebase,Firebase Cloud Messaging,我想让我的云函数向特定主题发送推送通知,这样就可以了。但是,当我添加“badge”字段时,会发生以下错误: Unknown name "badge" at 'message.notification': Cannot find field. 如果我想为iOS设备指定徽章编号,我应该怎么做?我的代码如下所示: exports.onAddLog = functions.database.ref("/NodesLog/{id}").onCreate((change, context) => {

我想让我的云函数向特定主题发送推送通知,这样就可以了。但是,当我添加“badge”字段时,会发生以下错误:

Unknown name "badge" at 'message.notification': Cannot find field.
如果我想为iOS设备指定徽章编号,我应该怎么做?我的代码如下所示:

exports.onAddLog = functions.database.ref("/NodesLog/{id}").onCreate((change, context) => {
const payload = {
    "topic": "Channel123",
    "notification": {
      "title": "Test-Title",
      "body": "Test-Body",
      "badge": "1"
    },
    "data": {
        "test": "test",
        "notId": "123"
    }
}

const promise : Promise<any> = admin.messaging().send(payload)
.catch(error => console.error("Error on send: " + error))
.then(sendSuccess => console.log("Notification send "))
.catch(() => console.error("What happened?"))

return promise;
})
exports.onAddLog=functions.database.ref(“/NodesLog/{id}”).onCreate((更改,上下文)=>{
常数有效载荷={
“主题”:“渠道123”,
“通知”:{
“标题”:“测试标题”,
“主体”:“测试主体”,
“徽章”:“1”
},
“数据”:{
“测试”:“测试”,
“notId”:“123”
}
}
const promise:promise=admin.messaging().send(有效负载)
.catch(error=>console.error(“发送时出错:+error))
。然后(sendSuccess=>console.log(“通知发送”))
.catch(()=>console.error(“发生了什么事?”))
回报承诺;
})

尝试将包含
徽章的
aps
节点添加到有效负载中

const payload = {

    ...

    "aps":{  
      "alert":"test alert",
      "badge":5,
      "sound":"default"
   }
}

问题是,徽章是iOS字段,它应该在另一个地方,正如阿里所说,它在“aps”对象中。但他没有说aps应该在哪里

例如,这应该是您的消息

{
  "message":{
     "topic": "Channel123",
      "notification": {
          "title": "Test-Title",
          "body": "Test-Body",
          "badge": "1"
      },
     "data": {
         "test": "test",
         "notId": "123"
     },
     "apns": {
       "payload": {
         "aps": {
           "badge": 5
         }
       }
     }
   }
 }

我以

为例,以下有效负载在Android和iOS上都适用:

payload = {
      notification: {
        "title": "Message Title",
        "body": "Message Body",
        "click_action": ".MainActivity",
        "badge": "1",
      },
      data: {
        "my_message_type": "foo",
        "my_id": "bar",
      },
    };

那么,为什么现在有两个徽章字段?