Giter VIP home page Giter VIP logo

Comments (11)

mypark avatar mypark commented on June 1, 2024

another interesting thing is that I've tried sending from the pushwoosh service, and I'm getting the same issue. It seems like that first androidbegin test link is the only one that gets a push message delivered to the galaxy s2 I'm testing with. Is there some sort of version compatibility where the older Galaxy s2s can't recieve messages from a newer GCM service?

from node-gcm.

Nonemoticoner avatar Nonemoticoner commented on June 1, 2024

I have the same problem. It is possible to achieve a succesful push with PHP code in GCM.php file on this website: http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/
Although, using PHP is not what I'm aiming to, so hopefully we could figure that out, together.

from node-gcm.

Nonemoticoner avatar Nonemoticoner commented on June 1, 2024

Okay, I have found the solution for my case. Hopefully, it's useful to you @mypark as well:

var sender = new gcm.Sender(googleApiKey);
var message = new gcm.Message();
message.addData('key1','testdarinodegcm');
message.delay_while_idle = 1;
var registrationIds = [];
registrationIds.push(reg_id);
sender.send(message, registrationIds, 4, function (err, result) {
console.log(result);
});

http://stackoverflow.com/questions/16410027/cant-receive-data-from-node-gcm
Firstly, it seemed stupid, but funnily it helped. I think devs should take a closer look on differences between making pushes in a usual way and that one provided by khurrum on StackOverFlow.

from node-gcm.

hypesystem avatar hypesystem commented on June 1, 2024

Hello Nonemoticoner! You are perfectly right. Somehow i didn't see this when I first read through the issue. It's a case of simple misunderstanding: the "boilerplate code" is not supposed to be a runnable example, but showing all the different ways the methods can be used. I see how this may cause confusion. Let's fix that right up!

from node-gcm.

hypesystem avatar hypesystem commented on June 1, 2024

How would you have reacted if this was the top of the Usage section?


Usage

To send a message you need to know the Registration IDs of your recipients, and have created an API key for GCM. Here is a simple example of how to send your first notification:

var gcm = require("node-gcm");

// Replace this key with your GCM API key
var sender = new gcm.Sender("YOUR API KEY");

// Replace these Registration IDs with actual Registration IDs
var registrationIds = [
  "FIRST_RECIPIENT'S_REGISTRATION_ID",
  "SECOND_RECIPIENT'S_REGISTRATION_ID"
];

var message = new gcm.Message({
  data: {
    testMessage: "This message is transmitted to the recipient device."
  }
});

// Actually send off the message
sender.send(message, registrationIds, function(err, result) {
  // Handle response from server
  if (err) console.error("Something went wrong!", err);
  else     console.log("Succesfully sent message. Got result", result);
});

The library provides quite a few ways to customize the notifications and the way they are sent. The following is a quick overview:

// Create a message
// ... with default values
var message = new gcm.Message();

... (section continues)

from node-gcm.

Nonemoticoner avatar Nonemoticoner commented on June 1, 2024

@hypesystem I believe the Usage is good enough. I've just talked to my friend with whom I'm working on GCM and it's been just Android application fault. I didn't have any flaws in my Node server-side scripting. I've just ran the previous piece of code I made and it worked for the newer Android app version.

@mypark It's most probably the device fault that push notification doesn't show.

from node-gcm.

hypesystem avatar hypesystem commented on June 1, 2024

Ah. Well that's a relief. Anyway, I think it is clear from @mypark's example that the usage section can lead to confusion.

He has the following lines:

// create a message with default values
var message = new gcm.Message();

// or with object values
var message = new gcm.Message({
  // ... (removed for bevity)
});

Here, he instantiates who messages as var message. This is syntactically broken in Javascript. And we do this in our Usage section. That, I think, is cause for reflection and potentially a revision.

I am going to keep thinking about how to best do this, but your input is valued :) Best of luck with your project.

from node-gcm.

hypesystem avatar hypesystem commented on June 1, 2024

Fixed by #110

from node-gcm.

Shivendra30 avatar Shivendra30 commented on June 1, 2024

I used the same code as provided by @Nonemoticoner above:

var sender = new gcm.Sender(googleApiKey);
var message = new gcm.Message();
message.addData('key1','testdarinodegcm');
message.delay_while_idle = 1;
var registrationIds = [];
registrationIds.push(reg_id);
sender.send(message, registrationIds, 4, function (err, result) {
console.log(result);
});

However, my app client app (react native Android) is still crashing when the notification is sent from the server.

From the server, I get the following success message:

{ multicast_id: 5346493375647405000,
  success: 1,
  failure: 0,
  canonical_ids: 0,
  results: [ { message_id: '0:1544767360018299%a0be8ac5f9fd7ecd' } ] }

What could be the possible issue now?

from node-gcm.

hypesystem avatar hypesystem commented on June 1, 2024

@Shivendra30 you would have to look at your client side (Android app) code to figure out what goes wrong on that end. FCM is telling you that delivery was a success, so the error must be in the app.

For this kind of problem, try StackOverflow or AskQuestions.Tech for help debugging. It's unfortunately outside of the scope of this library.

from node-gcm.

RenanRosa avatar RenanRosa commented on June 1, 2024

In my case, I rebooted the test device and now the notification works.

from node-gcm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.