我正在使用带有 nodejs(GCM、APNS)的 SNS 为 android 和 iOS 发送推送通知。我的有效载荷看起来像这样:
const payload = {
default: body,
GCM: {
notification: {
body,
title,
},
data: {
type
},
},
APNS: {
aps: {
alert: {
title,
body,
},
},
data: {
type
},
},
};
payload.GCM = JSON.stringify(payload.GCM);
payload.APNS = JSON.stringify(payload.APNS);
return JSON.stringify(payload);
移动设备收到带有标题和正文的通知,但 APNS 对象中不存在数据内部类型。是不是对象结构错了?
对于
APNS
,你可以尝试像这样解压你的数据对象:
const payload = {
default: body,
GCM: {
notification: {
body,
title,
},
data: {
type
},
},
APNS: {
aps: {
alert: {
title,
body,
},
},
type,
},
};
找不到任何可靠的答案,但我读过的关于这个主题的所有内容都表明 APNS JSON 有效负载仅支持 "aps"
对象之外的自定义
string键值对:
例如
{
"APNS": "{\"aps\":{\"content-available\":1},\"Foo1\":\"Bar\",\"Foo2\":123}"
}
例如
'APNS' : JSON.stringify({
'aps' : {
'alert' : $title,
'badge' : '0',
'sound' : 'default'
},
'id' : '123',
's' : 'section',
}),