适用于 iOS 的 Firebase 云消息传递本地化参数?



我正在尝试使用 FCM 为 iOS 撰写本地化的推送通知。我无法弄清楚消息的正确格式。这就是我现在格式化它的方式:

async function sendLocationLostNotification(notificationToken: string, newOwner: string, locationName: string) {
const message = {
name: "Location Lost Notification",
token: notificationToken,
apns: {
payload: {
aps: {
alert: {
loc_key: "location-lost-notification-body",
loc_args: [newOwner, locationName]
},
sound: "default"
}
}
}
};
return await admin.messaging().send(message)
}

这给了我以下错误:

src/index.ts:109:41 - error TS2345: Argument of type '{ name: string; token: string; apns: { payload: { aps: { alert: { loc_key: string; loc_args: string[]; }; sound: string; }; }; }; }' is not assignable to parameter of type 'Message'.
Type '{ name: string; token: string; apns: { payload: { aps: { alert: { loc_key: string; loc_args: string[]; }; sound: string; }; }; }; }' is not assignable to type 'TokenMessage'.
Types of property 'apns' are incompatible.
Type '{ payload: { aps: { alert: { loc_key: string; loc_args: string[]; }; sound: string; }; }; }' is not assignable to type 'ApnsConfig'.
Types of property 'payload' are incompatible.
Type '{ aps: { alert: { loc_key: string; loc_args: string[]; }; sound: string; }; }' is not assignable to type 'ApnsPayload'.
Types of property 'aps' are incompatible.
Type '{ alert: { loc_key: string; loc_args: string[]; }; sound: string; }' is not assignable to type 'Aps'.
Types of property 'alert' are incompatible.
Type '{ loc_key: string; loc_args: string[]; }' is not assignable to type 'string | ApsAlert | undefined'.
Type '{ loc_key: string; loc_args: string[]; }' has no properties in common with type 'ApsAlert'.
109     return await admin.messaging().send(message)

我已经阅读了Apple关于正确有效负载格式的文档,该格式引用自Firebase API参考。也看到了这个关于类似问题的答案,但 Jen Person 建议的格式给了我现在面临的相同错误。我能够使其静音的唯一方法是将titlebody添加到警报对象,但这会覆盖定位键。所以这些钥匙似乎是强制性的。此外,我尝试过分别使用body_loc_keytitle_loc_key,并且一次全部使用,但没有运气。

这里可能有什么问题?

事实证明,根据这些文档,ApsAlert使用locKeylocArgs

相关内容

  • 没有找到相关文章

最新更新