【发布时间】:2020-01-03 13:07:49
【问题描述】:
我正在尝试使用 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's docs 关于正确有效负载格式的信息,该格式引用自Firebase API reference。也看到了this answer 类似的问题,但 Jen Person 的建议格式给了我与我现在面临的相同的错误。我能够使其静音的唯一方法是将title 或body 添加到警报对象,但这会覆盖定位键。因此,这些密钥似乎是强制性的。此外,我尝试过分别使用body_loc_key 和title_loc_key,并且一次全部使用,但没有成功。
这可能是什么问题?
【问题讨论】:
标签: ios firebase firebase-cloud-messaging apple-push-notifications google-cloud-functions