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 208 forks source link

IOs does not receive notification when is in background #276

Closed irokhes closed 7 years ago

irokhes commented 7 years ago

I'm trying to send notifications to IOs devices but when is in background they are lost.

var sanitizedData = JSON.stringify(data);
        sanitizedData = JSON.parse(sanitizedData);
        var message = new gcm.Message({
            priority: 'high',
            content_available: true,
            data: sanitizedData,
        });
        var sender = new gcm.Sender(config.push.gcm.apiKey);
        var registrationIds = tokenArray;
        sender.send(message, {registrationTokens: registrationIds}, 4, function(err, result) {
            if (err) {
                return reject(err);
            } else {
                return resolve(result);
            }
        });

If I use the firebase console it works.

{
  "to": "XXXXXXXXXXX-TOKEN-XXXXXXXXXX",
  "content_available": true,
  "priority": "high",
  "data": {
    "type": "location",
    "data": {
      "valet": "58358a90c67acb0004d4742b",
      "status": "awaitingCustomer"
    }
  }
}

I have no idea how to fix it.

eladnava commented 7 years ago

@irokhes Set contentAvailable and not content_available in gcm.Message().

eladnava commented 7 years ago

Closing due to inactivity. Feel free to reopen if you still experience this issue.