简体   繁体   中英

Push notifications, from Parse-Server cloud code

I am trying to make Push notifications work, on Parse-Server (Heroku), with an iOS app.

At this point I can receive a notification in my iOS app, by running the command:

curl -X POST \
  -H "X-Parse-Application-Id: 12345678ABCDEFstuvwxyz" \
  -H "X-Parse-Master-Key: ABCDEF12345678stuvwxyz" \
  -H "Content-Type: application/json" \
  -d '{
        "where": {
          "deviceType": {
            "$in": ["ios"]
          }
        },
        "data": {
            "aps": {
              "alert": {},
              "content-available": 1
            },
            "title": "The Shining",
            "alert": {},
            "content-available": 1
        }
      }'\   https://myapp.herokuapp.com/parse/push

But now I must send a push notification from cloud code, namely from a Parse.Cloud.afterSave function.

This is what I have tried, following some sample code I found on the web, but it is not working :

  Parse.Cloud.afterSave("Item_List", (request) => {
    Parse.Push.send({
      ??????
      data: {"alert": "NOTIFICATION-FOR-USERS"},
      }, { success: function() {
         console.log("#### PUSH OK");
      }, error: function(error) {
         console.log("#### PUSH ERROR" + error.message);
      }, useMasterKey: true});
  });

What is the proper way to get what I want?

Try something like this:

Parse.Cloud.afterSave('Item_List', async () => {
  const query = new Parse.Query(Parse.Installation);
  query.equalTo('deviceType','ios');
  await Parse.Push.send({
    where: query,
    data: { alert: 'NOTIFICATION-FOR-USERS' },
    useMasterKey: true
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM