我正在尝试通过AWS SNS向GCM发送移动推送通知.根据最新的
GCM 3.0 documentation,可以包括“通知”有效载荷或“数据”有效载荷(或两者).如果您发送通知有效负载,GCM将负责为您显示最终用户设备上的通知.
@H_301_2@使用Amazon SNS控制台,我尝试发送仅通知的有效负载,但我遇到以下错误:
为了澄清,我想向GCM发送通知有效负载,并让它自动向用户显示警报,如文档中所述.现在,我开始怀疑SNS是否甚至将通知有效负载转发到设备.
@H_301_2@Invalid parameter: Message Reason: Invalid notification for protocol@H_301_2@我正在发送:
GCM: data key is expected in the json message (Service: AmazonSNS;
Status Code: 400; Error Code: InvalidParameter)
{ "GCM":"{\"notification\":{\"title\":\"Test Message\"}}" }@H_301_2@我怀疑这可能是一个问题,SNS仍然符合以前版本的GCM,因此它需要一个“数据”键,但我不确定.是否有其他人有类似的问题或有任何经验?谢谢! @H_301_2@编辑:
为了澄清,我想向GCM发送通知有效负载,并让它自动向用户显示警报,如文档中所述.现在,我开始怀疑SNS是否甚至将通知有效负载转发到设备.
解决方法
为了回答我自己的问题,我在他们的论坛上从AWS Support收到了以下内容:
@H_301_2@You are correct,SNS does not currently support GCM’s “notification”@H_301_2@因此,在SNS支持GCM通知有效负载之前,您必须通过扩展类GcmListenerService并覆盖onMessageReceived方法来自行处理通知的显示. @H_301_2@2015年10月10日更新:似乎SNS现在已经实现了对GCM通知负载的支持.如果同时包含“数据”和“通知”有效负载,则“通知”将优先.我只在SNS上观察到这种行为,但未找到任何AWS博客/文章宣布这一点.
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.