Firebase 云消息传递 - iOS 徽章

pma*_*ax1 3 ios firebase firebase-cloud-messaging

我希望我的 Cloud Function 向特定主题发送推送通知,这很好用。但是,当我添加“徽章”字段时,会出现以下错误:

Unknown name "badge" at 'message.notification': Cannot find field.
Run Code Online (Sandbox Code Playgroud)

如果我想为 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;
})
Run Code Online (Sandbox Code Playgroud)

m1s*_*sh0 9

问题是徽章是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
         }
       }
     }
   }
 }
Run Code Online (Sandbox Code Playgroud)

我从这里拿了例子