gpt4 book ai didi

android - 使用 AWS SNS 将仅通知负载发送到 GCM

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:00:46 25 4
gpt4 key购买 nike

我正在尝试通过 AWS SNS 向 GCM 发送移动推送通知。根据最新GCM 3.0 documentation ,一个可以包括“通知”有效载荷或“数据”有效载荷(或两者)。如果您发送通知负载,那么 GCM 将负责为您在最终用户设备上显示通知。

使用 Amazon SNS 控制台,我尝试发送仅通知负载,但遇到以下错误:

Invalid parameter: Message Reason: Invalid notification for protocol GCM: data key is expected in the json message (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter)

我要发送:

{
"GCM":"{\"notification\":{\"title\":\"Test Message\"}}"
}

我怀疑这可能是 SNS 仍然符合以前版本的 GCM 的问题,因此它需要一个“数据” key ,但我不确定。有没有其他人有类似的问题或对此有任何经验?谢谢!

编辑:澄清一下,我想向 GCM 发送一个通知有效负载,并让它按照文档中的描述自动向用户显示警报。现在,我开始怀疑 SNS 是否将通知负载转发到设备。

最佳答案

为了回答我自己的问题,我在他们的论坛上收到了来自 AWS Support 的以下信息:

You are correct, SNS does not currently support GCM's "notification" payload type as described in their documentation. SNS supports the initial "data" payload type only but we are actively working on a solution to support the "notification" type. In the meantime, the "data" payload works the same except the client app is responsible for processing data messages as it has in the past.

因此,在 SNS 支持 GCM 通知负载之前,您必须通过扩展类 GcmListenerService 并覆盖方法 onMessageReceived 来自行处理通知的显示。

更新 10/2015:似乎 SNS 现在已经实现了对 GCM 通知负载的支持。如果您同时包含“数据”和“通知”有效负载,则“通知”将优先。我只在 SNS 上观察到这种行为,但找不到任何宣布这一点的 AWS 博客/文章。

关于android - 使用 AWS SNS 将仅通知负载发送到 GCM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31883309/

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