首页 > 解决方案 > iOS、Node.js:Firebase 推送通知 JSON 签名

问题描述

Firebase 文档要求像这样实现,它在 node.js 服务器上获得成功返回值。但是通知没有送达。

从 Firebase 云消息传递控制台,所有通知/消息都会被传递。除了以下情况,普通的 APNS 也可以使用。

这个特定的 JSON 签名不会向 APNS 确认。当我提供与 APNS 兼容的 JSON 时,Firebase 会返回错误。

// This registration token comes from the client FCM SDKs.
var registrationToken = 'YOUR_REGISTRATION_TOKEN';

var message = {
  data: {
    score: '850',
    time: '2:45'
  },
  token: registrationToken
};

// Send a message to the device corresponding to the provided
// registration token.
admin.messaging().send(message)
  .then((response) => {
    // Response is a message ID string.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

怎样做才能工作?

标签: iosswiftfirebasefirebase-cloud-messaging

解决方案


我从 Google 的 Firebase 示例代码中找到了这个。而且,它有效。

{
        "token": "<<YOUR FCM TOKEN>>",
        "notification": {
            "body": "Notification from FCM",
            "title": "FCM Notification"
        },
        "android": {
            "notification": {
                "click_action": "android.intent.action.MAIN"
            }
        },
        "apns": {
            "headers": {
                "apns-priority": "10"
            },
            "payload": {
                "aps": {
                    "badge": 1
                }
            }
        }
    }

推荐阅读