亚马逊SNS中的徽章计数选项 [英] Badge count option in amazon SNS

查看:150
本文介绍了亚马逊SNS中的徽章计数选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to get badge count in my application. I am using amazon SNS service. Here is my code

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选项?

I need to know where I can add badge option here?

谢谢!

推荐答案

我们可以将json消息发送到AWS SNS,以将推送通知发送到应用程序端点.这样我们就可以发送平台(APNS,FCM等)的特定字段和自定义内容.

We can send json message to AWS SNS to send push notification to application endpoint. Which allows us to send platform (APNS, FCM etc) specific fields and customizations.

用于APNS的json消息示例是

Example json message for APNS is,

{
"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文档,

If you need to support multiple platforms then as per AWS docs,

要将消息发送到在多个平台(例如FCM和APNS)的设备上安装的应用程序,您必须首先将移动终端节点订阅Amazon SNS中的主题,然后将消息发布到 topic .

可以找到 AWS SNS文档可在此处找到将特定于平台的自定义有效负载发送到移动设备

AWS SNS documentation can be found here Send Custom, Platform-Specific Payloads to Mobile Devices

这篇关于亚马逊SNS中的徽章计数选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆