ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 206 forks source link

Only last push notification show upon sending multiple notifications #164

Closed abhaygarg closed 8 years ago

abhaygarg commented 8 years ago
var gcm = require('node-gcm');
var message = new gcm.Message();
var user = require("./UserModel").User
var mongoose = require("mongoose")
mongoose.connect('mongodb://localhost/myapp');
//API Server Key
var sender = new gcm.Sender('xxxxx');
var registrationIds = [];
var bodyParser = require('body-parser')

// Value the payload data to send...
//message.addData('message', "\u270C Peace, Love \u2764 and Life \u2706!");
message.addData('message', 3);
message.addData('title', 'Push Notification Sample');
//message.addData('soundname','beep.wav'); //Sound to play upon notification receipt - put in the www folder in app
//message.collapseKey = 'demo';
//message.delayWhileIdle = true; //Default is false
message.timeToLive = 10000;// Duration in seconds to hold in GCM and retry before timing out. Default 4 weeks (2,419,200 seconds) if not specified.
console.log(registrationIds);

sender.send(message, user.mobileId, 4, function (a,result) {

    console.log("ok",a);
    console.log("why",result);
    //console.log("ok",registrationIds);
   });

So our notification send successfully but the problem is only latest push notification show , we wants that if we send multiple notification to single user then different notification shows

hypesystem commented 8 years ago

Hi @abhaygarg!

I am having some trouble understanding your question. In the code you have shown you are only sending one notification, and you have not shown any output from the given code (what happens, what you expected to happen, etc).

abhaygarg commented 8 years ago

Thanks for reply, Actually this code is used for sending push notification , and we placed this code in a method and calls every time when notification is generated ,

sender.send(message, user.mobileId, 4, function (a,result) {
  console.log("ok",a);
    console.log("why",result);
    //console.log("ok",registrationIds);
   });

So our problem is lets suppose we send push notification to a user and user does not open that notification and on server there is another notification is generated then we send another push notification to that user . So after that the notification is updated and new notification is show on mobile and previous did not

eladnava commented 8 years ago

@abhaygarg this sounds like a client-side implementation issue - are you sending to iOS or Android?

If you're sending to Android devices, make sure you aren't using the same NOTIFICATION_ID when issuing out different notifications, as previous ones will be overriden:

// Sets an ID for the notification - make sure to change this for different notifications
int mNotificationId = 001;

// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

// Builds the notification and issues it
mNotifyMgr.notify(mNotificationId, mBuilder.build());
abhaygarg commented 8 years ago

We use IONIC framework at client site , upon debugging we find that we send the same notId , now we send different notId from server and problem is solved Thanks for your support

manojbadam commented 8 years ago

Hi abhaygarg, eladnava

I'm sending the notification Id as below. But i can see only the last notification message. Do i need to make any changes at the client side ? We are using the Ionic framework at client side.

        var message = new gcm.Message();
        message.addData('message',msg.details.message);
        message.addData('title',msg.details.appId);
        message.addData('msgcnt','1');
        **message.addData('NOTIFICATION_ID',this.androidcount++);**

sender.send(message, registrationIds, function (err, result) { });

Thanks Manoj Badam

hypesystem commented 8 years ago

@manojbadam please create a new issue with your question, it does not seem to be the same as the original question :smile: