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

Not receiving notifications - ios #350

Closed ademir10 closed 3 years ago

ademir10 commented 3 years ago

Hi guys! I'm trying to send notifications using this plugin and everything is working fine with Android devices but i can't make it work with ios devices.

I'm sure that everything is okay with firebase because when i try to send a test message from there, i receive the test message, but when i try to do the same through my NodeJS API, it's working only to Android devices.

Do you know if need to make something else when i send messages to ios?

This is my code: var gcm = require('node-gcm'); // Server token firebase var sender = new gcm.Sender('AAAAVfnX-18:APA91bEuukPhVF-.............'); // Prepare a message to be sent var message = new gcm.Message({ data: { key1: 'Test message here' } }); // Token generated in my Front-End (App) var regTokens = ['cXSdaAPtV0X8h1SJ5NjjDC:APA91bHv16gWO8185NytrOtw9LHSuViJMOOctRAwkE4OoCIFUIrDAmYe7-MtHp4pXimgO9muoNoINtjxZoeDbA4tovV6pjNdXoTTfA_8RrGP51CFzPAgA1bJR3uPEpZEpp3EgOv3flEb']; // Actually send the message sender.send(message, { registrationTokens: regTokens }, function (err, response) { if (err) console.error(err); else console.log(response); });

Any suggestion? thank you.

eladnava commented 3 years ago

Hi @ademir10, For iOS, you must specify the notification key with a body:

var message = new gcm.Message({
    data: {
        key1: 'message1',
        key2: 'message2'
    },
    notification: {
        title: "Hello, World",
        icon: "ic_launcher",
        body: "This is a notification that will be displayed if your app is in the background."
    }
});
ademir10 commented 3 years ago

Hi @ademir10, For iOS, you must specify the notification key with a body:

var message = new gcm.Message({
  data: {
      key1: 'message1',
      key2: 'message2'
  },
  notification: {
      title: "Hello, World",
      icon: "ic_launcher",
      body: "This is a notification that will be displayed if your app is in the background."
  }
});

Yep! I found it after couple hours hahahah. Thank you my dear friend! God bless you