简体   繁体   中英

Getting wrong data throug GCM push notification

I am building application using phonegap build and pushnotification plugin. 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)

{
    "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.

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. Hope it helps some1 else with similar issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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