【问题标题】:Managing Parse _Installation class after user deletes and reinstalls app用户删除并重新安装应用程序后管理 Parse _ 安装类
【发布时间】:2017-07-07 15:32:07
【问题描述】:

因此,我们遇到了一些问题,即人们无法通过我们的应用收到推送通知。

我们发现,当用户删除并重新安装应用程序同时给我们推送权限时,它会在 _Installation 类中创建另一行。

如果我们手动删除所有行并且用户安装应用并启用推送,则推送现在发送给用户。

所以问题是处理这种情况的最佳方法是什么,以确保每个人在安装或重新安装后在 _Installation 类中只有一行。

我正在尝试这个云功能,但它没有返回任何结果,即使在数据库中它为该用户提供了额外的行。

``

  Parse.Cloud.beforeSave(Parse.Installation, function(request, response) {

  var userId = request.object.get("user").id;
  console.log("user id = " + userId)

  query = new Parse.Query("_Installation");
  query.equalTo("user", {__type: "Pointer", className: "User", objectId: userId})

  query.find({ useMasterKey: true }).then(function(installations) {  
      console.log("Successfully retrieved " + installations.length + " item");
      console.log(installations[0])
      console.log(installations)
      console.log('worked');
      response.success("The user has been authorized.");
    }, function(error) {
      console.log('failed')
      response.error("user authorization failed");
    });

});

``

来自解析的控制台日志

Feb 20 17:09:33 likemoji-stage app/web.1: user id = t6yQIXiwvG Feb 20 17:09:33 likemoji-stage app/web.1: Successfully retrieved 0 item Feb 20 17:09:33 likemoji-stage app/web.1: undefined Feb 20 17:09:33 likemoji-stage app/web.1: [] Feb 20 17:09:33 likemoji-stage app/web.1: worked

【问题讨论】:

  • 我正在尝试这个,但没有收到任何结果,即使在那个类中它显然有额外的行。

标签: javascript ios swift parse-platform


【解决方案1】:

好的,万一有人遇到这个问题,我就是这样解决的。可能还有其他方法可以做到这一点。

Parse.Cloud.afterSave(Parse.Installation, function(request, response) {
  // get the parse user object to use in the query below
  var user = request.object.get("user")
  // actual query
  var query = new Parse.Query(Parse.Installation)
  query.equalTo("user", user)
  query.descending("createdAt")  
  query.find({ useMasterKey: true }).then(function(results) {                 
    if(typeof results !== 'undefined' && results.length > 0) {
      return Parse.Object.destroyAll(results, {useMasterKey: true});
    }
  }).then(function() {
      // Done
      //console.log('finished')
  }, function(error) {
      // Error
      //console.log('failed')
  });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-06
    相关资源
    最近更新 更多