【问题标题】:Badge count option in amazon SNS亚马逊 SNS 中的徽章计数选项
【发布时间】:2019-09-01 21:35:29
【问题描述】:

我需要在我的应用程序中获取徽章计数。我正在使用亚马逊 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 选项?

谢谢!!!

【问题讨论】:

    标签: node.js amazon-sns serverless-framework serverless aws-serverless


    【解决方案1】:

    我们可以向 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 文档,

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

    可以在APNS Payload Key Reference 找到特定于 APNS 的负载密钥。

    AWS SNS 文档可以在这里找到Send Custom, Platform-Specific Payloads to Mobile Devices

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-08
      • 2023-04-10
      • 2015-02-21
      • 2014-01-20
      • 2017-02-25
      • 1970-01-01
      • 1970-01-01
      • 2016-11-26
      相关资源
      最近更新 更多