使用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,因此它需要一个“数据”键,但我不确定.是否有其他人有类似的问题或有任何经验?谢谢!
编辑:
为了澄清,我想向GCM发送通知有效负载,并让它自动向用户显示警报,如文档中所述.现在,我开始怀疑SNS是否甚至将通知有效负载转发到设备.
解决方法
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方法来自行处理通知的显示.
2015年10月10日更新:似乎SNS现在已经实现了对GCM通知负载的支持.如果同时包含“数据”和“通知”有效负载,则“通知”将优先.我只在SNS上观察到这种行为,但未找到任何AWS博客/文章宣布这一点.