Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push notification not working main.js #1740

Closed
Twizzlerfw opened this issue May 10, 2016 · 5 comments
Closed

Push notification not working main.js #1740

Twizzlerfw opened this issue May 10, 2016 · 5 comments

Comments

@Twizzlerfw
Copy link

I am now on the new parse open source server and I am trying to send a push notification using the cloud main.js. I have sent a push using curl but am having a problem with javascript. Here is the code I have.

Parse.Cloud.define("PushNotification", function(request, response) {
  console.log('sending push');
var Installation = new Parse.Query(Parse.Installation);
  console.log(Installation);

Parse.Push.send({

    where: Installation,
  data: {
    alert: request.params.Message,
    badge: 0,
    sound: 'default'
  }
}, {
  useMasterKey: true,
  success: function() {
    // Push sent!
  console.log('Push sent');
        response.success('success');

  },
  error: function(error) {
    // There was a problem :(
          response.error("Error push did not send");
            console.log('sending push error: '+error);


  }
});

It says that it sent but It did not. If any one could help that would be great!

@bohemima
Copy link
Contributor

Start the parse-server with VERBOSE=1 and see if there are any hints to help debugging in the console.

@dannyvanderzande
Copy link

Have you tried adding Parse.Cloud.useMasterKey(); as the first line of your function. It seems to work for me.

@palej
Copy link

palej commented May 11, 2016

I'm using another way, here is code example with error function to understand where this row should be:
error: function(error){
console.error(error);
},
useMasterKey: true

But can confirm that pushes doesn't sends. Actually, they sometimes sends, and sometimes no.
Enabled VERBOSE=1 but not a lot information:
parse-server-push-adapter GCM2016-05-11 XX:XX:XX +XX:00: sending to 569 devices
parse-server-push-adapter GCM2016-05-11 XX:XX:XX +XX:00: GCM Response: {
and so on, pushes sent.
In few minutes:
parse-server-push-adapter GCM2016-05-11 XX:XX:XX +XX:00: sending to 569 devices
and nothing more in logs. No pushes received.
Directly after that, login to Dashboard and sent test push:
parse-server-push-adapter GCM2016-05-11 XX:XX:XX +XX:00: sending to 1 device
parse-server-push-adapter GCM2016-05-11 XX:XX:XX +XX:00: GCM Response: {
Received immideately.

@Twizzlerfw
Copy link
Author

Twizzlerfw commented May 12, 2016

At the top I had to enter Parse.serverURL = 'http://URL/parse';
and I had to use this code.

Parse.Cloud.define("PushNotification", function(request, response) {
  console.log('sending push');
var Installation = new Parse.Query(Parse.Installation);
  console.log(Installation);

Parse.Push.send({
useMasterKey: true,
    where: Installation,
  data: {
    alert: request.params.Message,
    badge: 0,
    sound: 'default'
  }
}, {
  useMasterKey: true,
  success: function() {
    // Push sent!
  console.log('Push sent');
        response.success('success');

  },
  error: function(error){
console.error(error);
}

});
});

@pdkcoder
Copy link

@palej Did you solve your problem? I am getting similar issue, I can send push from dashboard, but with cloud code, my phone can not receive

I am getting same log for both cases:

verbose: {
  "headers": {
    "X-Parse-Push-Status-Id": "AQvx589aUT"
  },
  "response": {
    "result": true
  }
}
verbose: sending push to 16 installations
verbose: sent push! 12 success, 1 failures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants