ios - 如何为使用 AWS SNS 创建的远程推送通知设置 APNS 通知标识符?

标签 ios amazon-web-services apple-push-notifications amazon-sns

我在后端使用 AWS SNS 开发工具包向我的应用程序发送远程通知,我需要能够设置通知标识符,以便某些通知默认替换以前发送的副本,如 iOS developer docs 中所述。 :

If you use the same identifier when scheduling a new notification, the system removes the previously scheduled notification with that identifier and replaces it with the new one.

使用本地通知很容易做到这一点,因为它们是在应用程序中安排的,您可以在安排通知时设置通知标识符。

但是,对于远程通知,我似乎找不到任何方法来使用 SNS SDK 设置通知标识符。 (在用 .NET 编写的 Lambda 中)。

根据 API 引用,SNS returns a response with a message ID (这可能是通知标识符),但我自己看不到任何设置标识符的方法。

有人知道怎么做吗?还是 SNS 根本不允许这样做?

最佳答案

您可以自定义负载,如 AWS 所述:https://docs.aws.amazon.com/sns/latest/dg/mobile-push-send-custommessage.html

When sending platform-specific payloads in messages using the Amazon SNS console, the data must be key-value pair strings and formatted as JSON with quotation marks escaped. The following example, including formatting and spaces for readability, shows a sample custom message for the GCM platform with key-value pair within the message body and formatted as JSON.

{ "GCM":"{ "data":{ "message":"Check out these awesome deals!", "url":"www.amazon.com" } }" }

您可以将您的 ID 添加为自定义字段。

编辑:如果您需要添加 header ,您可能希望通过 Lambda 函数代理请求:https://docs.aws.amazon.com/sns/latest/dg/sns-lambda.html 这是一个显示如何使用 Lambda 添加响应 header 的线程:Setting http response header from AWS lambda

关于ios - 如何为使用 AWS SNS 创建的远程推送通知设置 APNS 通知标识符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52021582/

相关文章:

ios - UITableViewCell 中的 UITextField 使用单元格的 imageView

ios - writeCopy 后出现 RLMException "Realm at path ' ' already opened with different encryption key"(toFile :, 加密 key :)

ios - 如何以编程方式选择嵌入式 View 的 Controller ?

java - 如何在AWS Java SDK中设置连接类型? - HTTPS 与 HTTP

amazon-web-services - INFO:关闭了EC2实例安全组上的端口22

ios - 使 getNotificationSettings 返回而不是使用完成 block

c++ - "string.h"在为 iOS 构建 qt 应用程序时未找到消息

security - 在 Amazon S3 中,我需要什么权限才能获取对象的 HEAD?

php - 检查表中是否存在值或处理MySQL的唯一约束异常?

apple-push-notifications - 如何在 Swift 3 中将 apns 数据转换为字符串?