简体   繁体   English

推送通知,来自 Parse-Server 云代码

[英]Push notifications, from Parse-Server cloud code

I am trying to make Push notifications work, on Parse-Server (Heroku), with an iOS app.我正在尝试使用 iOS 应用程序在 Parse-Server (Heroku) 上使推送通知工作。

At this point I can receive a notification in my iOS app, by running the command:此时,我可以通过运行以下命令在我的 iOS 应用程序中收到通知:

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.但现在我必须从云代码发送推送通知,即从 Parse.Cloud.afterSave 函数。

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
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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