Dmi*_*nko 4 push-notification firebase google-cloud-functions firebase-cloud-messaging
我正在尝试使用特定于平台的配置通过Firebase Cloud Functions发送推送通知。我从https://firebase.google.com/docs/cloud-messaging/send-message获得了以下配置
var message = {
notification: {
title: '$GOOG up 1.43% on the day',
body: '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
},
data: {
channel_id: threadId,
},
android: {
ttl: 3600 * 1000,
notification: {
icon: 'stock_ticker_update',
color: '#f45342',
},
},
apns: {
payload: {
aps: {
badge: 42,
},
},
},
};
Run Code Online (Sandbox Code Playgroud)
但是有错误 admin.messaging().sendToDevice(deviceToken, message)
Messaging payload contains an invalid "android" property. Valid properties are "data" and "notification"
知道这里有什么问题吗?还是一些适用于iOS / Android平台的正确配置示例?
sendToDevice()是使用旧版FCM HTTP端点的功能。传统端点不提供特定于平台的字段。为了获得该功能,您可以通过该send()功能使用新的端点。您可能需要更新您的Admin SDK版本。您可以在此处的文档中查看示例。
例如,对于您提供的代码,您将发送如下消息:
let message = {
notification: {
title: '$GOOG up 1.43% on the day',
body: '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
},
data: {
channel_id: threadId,
},
android: {
ttl: 3600 * 1000,
notification: {
icon: 'stock_ticker_update',
color: '#f45342',
},
},
apns: {
payload: {
aps: {
badge: 42,
},
},
},
token: deviceToken,
};
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);
});
Run Code Online (Sandbox Code Playgroud)
注意,设备令牌现在在message对象中。
| 归档时间: |
|
| 查看次数: |
631 次 |
| 最近记录: |