简体   繁体   English

Amazon SNS 移动推送:如何在 GCM 和 APNS 上设置推送的到期时间

[英]Amazon SNS Mobile push: How do I set expiration time for push on GCM and APNS

I am trying to control a push message lifetime.我正在尝试控制推送消息的生命周期。

I would like to set expiration time for push message on GCM and APNS using SNS.我想使用 SNS 在 GCM 和 APNS 上设置推送消息的过期时间。 (eg GCM's "time_to_live" option) (例如 GCM 的“time_to_live”选项)

How do I set it?我该如何设置? or, SNS is can not control it?或者,SNS是无法控制的吗?

Thanks.谢谢。

I found answer by myself. 我自己找到了答案。

SNS is can not manage mobile message lifetime now. SNS现在无法管理移动消息的生命周期。

Thanks. 谢谢。

================= =================

EDIT. 编辑。

Amazon SNS added TTL control for mobile push notification. Amazon SNS为移动推送通知添加了TTL控件。

http://docs.aws.amazon.com/sns/latest/dg/sns-ttl.html http://docs.aws.amazon.com/sns/latest/dg/sns-ttl.html

I'll leave this here if someone comes across the same question and does not find the official docs straightforward about the config as there is no example on the official AWS.如果有人遇到同样的问题并且没有找到关于配置的官方文档,我会把它留在这里,因为官方 AWS 上没有示例。 If you are using aws-sdk in node you can use this snippet.如果您在节点中使用aws-sdk ,则可以使用此代码段。

import AWS from 'aws-sdk';

AWS.config.update({region: 'us-east-1'});

const params = {
  'TargetArn' : '<ARN ENDPOINT>',
  'MessageStructure' : 'json',
  'MessageAttributes': {
    'AWS.SNS.MOBILE.APNS_SANDBOX.TTL': {
      DataType: 'Number',
      StringValue: '7200' // value in seconds
    },
    'AWS.SNS.MOBILE.APNS.TTL': {
      DataType: 'Number',
      StringValue: '7200' // value in seconds
    },
    'AWS.SNS.MOBILE.FCM.TTL': {
      DataType: 'Number',
      StringValue: '7200' // value in seconds
    },
  },
  'Message' : JSON.stringify({
    "GCM": JSON.stringify({
      content_available: true,
      priority: "high",
      notification: {
        body: '<Your message>',
        title: "<Your title>",
        android_channel_id: "<Your channel>",
      }
    }),
    "APNS_SANDBOX" : JSON.stringify({
      'aps' : { 'alert' : '<Your message>' },
    }),
    "APNS" : JSON.stringify({
      'aps' : { 'alert' : '<Your message>' },
    }),
  })
};

sns.publish(params, (error, response) => {});

For Windows, Amazon, Baidu service setting parameters see official docs: Windows、亚马逊、百度服务设置参数见官方文档:

https://docs.aws.amazon.com/sns/latest/dg/sns-ttl.html https://docs.aws.amazon.com/sns/latest/dg/sns-ttl.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM