gpt4 book ai didi

node.js - 亚马逊 SNS 中的徽章计数选项

转载 作者:搜寻专家 更新时间:2023-10-31 23:19:15 24 4
gpt4 key购买 nike

我需要在我的应用程序中获取徽章计数。我正在使用亚马逊 SNS 服务。这是我的代码

AWS.config.update({
accessKeyId: 'XXXXXXX',
secretAccessKey: 'XXXXXXX'
})
AWS.config.update({ region: 'XXXXXXX' })
const sns = new AWS.SNS()
const params = {
PlatformApplicationArn: 'XXXXXXX',
Token: deviceToken
}
sns.createPlatformEndpoint(params, (err, EndPointResult) => {
const client_arn = EndPointResult["EndpointArn"];
sns.publish({
TargetArn: client_arn,
Message: message,
Subject: title,
// badge: 1
}, (err, data) => {
})
})

我需要知道在哪里可以添加 badge 选项?

谢谢!!!

最佳答案

我们可以向 AWS SNS 发送 json 消息以向应用端点发送推送通知。这使我们能够发送平台(APNS、FCM 等)特定字段和自定义项。

APNS 的示例 json 消息是,

{
"aps": {
"alert": {
"body": "The text of the alert message"
},
"badge": 1,
"sound": "default"
}
}

这是您可以发送请求的方式,

   var sns = new AWS.SNS();
var payload = {
default: 'This is the default message which must be present when publishing a message to a topic. The default message will only be used if a message is not present for
one of the notification platforms.',
APNS: {
aps: {
alert: 'The text of the alert message',
badge: 1,
sound: 'default'
}
}
};

// stringify inner json object
payload.APNS = JSON.stringify(payload.APNS);
// then stringify the entire message payload
payload = JSON.stringify(payload);

sns.publish({
Message: payload, // This is Required
MessageStructure: 'json',
TargetArn: {{TargetArn}} // This Required
}, function(err, data) {
if (err) {
console.log(err.stack);
return;
}
});
});

如果您需要支持多个平台,那么根据 AWS 文档,

To send a message to an app installed on devices for multiple platforms, such as FCM and APNS, you must first subscribe the mobile endpoints to a topic in Amazon SNS and then publish the message to the topic.

可以找到 APNS 特定的有效载荷 key APNS Payload Key Reference .

可在此处找到 AWS SNS 文档 Send Custom, Platform-Specific Payloads to Mobile Devices

关于node.js - 亚马逊 SNS 中的徽章计数选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57691028/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com