简体   繁体   English

通过GCM推送通知获取错误的数据

[英]Getting wrong data throug GCM push notification

I am building application using phonegap build and pushnotification plugin. 我正在使用phonegap构建和pushnotification插件构建应用程序。 I can't understand why is field "event" (inside "data")always "message" even if i dont send it at all or if i send something else like "event":"registration". 我什至不知道为什么“事件”(在“数据”内部)总是“消息”,即使我根本不发送它,或者我发送诸如“事件”:“注册”之类的东西。 Also i dont get any other fields i include in data, like "message_id" and sort... Here is example of rest request i am using for testing and it works fine (i can change message and it always sends correct message) 我也没有得到我包含在数据中的任何其他字段,例如“ message_id”和排序...这是我用于测试的其余请求的示例,它工作正常(我可以更改消息,并且总是发送正确的消息)

{
    "data" : {
        "event":"message",
        "message":"some message"
    },
    "registration_ids" : ["APA9..."]
}

but when I try to send this: 但是当我尝试发送此:

{
    "data" : {
        "event":"newMessage",
        "message_id":134,
        "group":1    
    },
    "registration_ids" : ["APA91b..."]
}

I still get event "message" and dont even see other fields in code. 我仍然收到事件“消息”,甚至看不到代码中的其他字段。 Here is my code: 这是我的代码:

onNotificationGCM: function(e) {
    switch( e.event )
    {
        case 'message':
           alert(e.message);
        break;

        case 'newMessage':
          alert ('entered newMessage');
          var id = e.message_id;
          var grp = e.group;
          //something to do with theese two but it never enters here 
        break;

        default:
          alert('An unknown GCM event has occurred');
          break;
    }

It never gets to alert ('entered newMessage') and if I put alerts of fields group and e.message_id in case 'message', they are undefined. 它永远不会发出警报(“输入newMessage”),如果我将字段组和e.message_id的警报放在“ message”的情况下,则它们是未定义的。

Hope someone can help, thanks in advance (sorry for bad english). 希望有人能提供帮助,在此先感谢(对不起,英语不好)。

Ok, issue was with push plugin from phonegap build, it forwarded only those two fields... Now it is updated and plugin now forwards all arguments sent under "payload" field. 好的,问题是来自phonegap构建的推插件,它仅转发了这两个字段...现在已更新,插件现在转发了在“有效载荷”字段下发送的所有参数。 Hope it helps some1 else with similar issue 希望它可以帮助其他人解决类似问题

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

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