How to send Push Notifications with Parse.com Cloudcode

后端 未结 3 856
暖寄归人
暖寄归人 2021-01-07 05:22

I want to send a Push Notification with Cloudcode on Parse.com.

The push notification should be sent to all android devices that are subscribed to a specific channe

相关标签:
3条回答
  • 2021-01-07 06:07

    1) Add

    Parse.initialize("APPLICATION_ID", "JAVASCRIPT_KEY");
    

    2) Enable Java scripts push notification in Parse.com

    3) Download Java script project "parse-js-blank"

    4) Create installation object with Channel

    5) send request.

    Parse.Push.send({
              channels: [ "Giants","Vaquar" ],
              data: {
                alert: "Vaquar Alert Message."
              }
            }, {
              success: function() {
                // Push was successful
              },
              error: function(error) {
                // Handle error
                alert("(error"+eval(error));
              }
            });
    

    Reference: https://parse.com/docs/js/guide#push-notifications

    0 讨论(0)
  • 2021-01-07 06:15

    You don't need a query to send a push to a channel. Just call Parse.Push.send and add a channel array to the data object.

    Parse.Push.send({
            channels: [ "channel_name" ],
            data: {
                alert: "Alert message"
            }
        }, {
            success: function () {
                response.success("Push was sent");
            },
            error: function (error) {
                response.error("Could not send push " + error)
            }
        });
    

    Be sure to not use spaces and Capital letters in channel names. The channel will not be added to the subscribed channels in the backend.

    0 讨论(0)
  • 2021-01-07 06:16

    All you need is an installation query, along with an accompanying push. For example:

    var pushQuery = new Parse.Query(Parse.Installation);
    pushQuery.containedIn("user", userlist);
    Parse.Push.send({
      where: pushQuery, 
      data: {
         alert: "Your push message here!"
      }
    }, {
      success: function() {
        response.success("pushed");
      }, error: function(error) {
       reponse.error("didn't push");
      }
    });
    

    That installation query can be a query based on a channel, and there are other specifications you can make for the push query, given in the documentation:

    Parse Docs

    0 讨论(0)
提交回复
热议问题