2

我即将开始为我的大学期末项目开发一个食谱 Android 应用程序,我希望用户能够将食谱添加到数据库中。但是,我不希望立即添加数据,但我希望在有人想要添加食谱时收到通知,以便我自己确认。顺便说一句,我正在使用 back{4} 应用程序。

我怎样才能以不那么复杂的方式做这样的事情?我正在考虑在应用程序本身中为自己创建一个管理员帐户,但是有没有办法将通知发送到所述帐户?我还希望能够在应用程序中通过一个简单的“确认”按钮来确认添加食谱,那么这是否需要我为待处理的食谱创建一个额外的类?在任何情况下我都需要一个管理员帐户吗?

4

1 回答 1

1

这一切都可以通过使用云代码来实现。

Parse.cloud.define("addRecipe", function(request, response) {
    const query = new Parse.Query("recipe");
    query.set("name", "name");
    query.save({
         success function(result) {
              response(result);
              //call push notification function from client or from cloud code when the error is nil 
         },
         error: function(result, error) {
          response(error);
          }
    });
});

这是使用云代码推送通知的示例。由于安全原因,客户端不再允许推送通知。你应该订阅这个频道

Parse.Cloud.define("pushsample", function (request, response) {
    Parse.Push.send({
        channels: ["channelName"],
        data: {
            title: "Hello!",
            message: "Hello from the Cloud Code",
        }
   }, {
        success: function () {
            // Push was successful
            response.sucess("push sent");
        },
        error: function (error) {
        // Push was unsucessful
        response.sucess("error with push: " + error);
        },
        useMasterKey: true
   });
});

您还应该为您的应用程序实现一些逻辑,以显示由管理员确认的食谱。

var recipe = Parse.Object.extend("recipe");
var query = new Parse.Query(recipe);
query.equalTo("confirm", true);
query.find({
  success: function(results) {
    //it will display recipes confirmed
  },
  error: function(error) {
    alert("Error: " + error.code + " " + error.message);
  });

您还应该在您的应用程序或网站中设置管理系统

于 2017-11-14T05:09:21.377 回答