javascript - 用户删除并重新安装应用程序后管理 Parse _Installation 类

标签 javascript ios swift parse-platform

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

我们发现,当用户删除并重新安装应用程序,同时向我们提供另一个推送权限时,它会在 _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:成功检索到 0 项 Feb 20 17:09:33 likemoji-stage app/web.1:未定义 Feb 20 17:09:33 likemoji-stage app/web.1: [] Feb 20 17:09:33 likemoji-stage app/web.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')
  });
});

关于javascript - 用户删除并重新安装应用程序后管理 Parse _Installation 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42309239/

相关文章:

ios - SVG 作为背景图像会使 ios 上的 safari 崩溃

ios - 如何在Navbar上更改这些颜色?

ios - 将 UICollectionView 调整为内容大小

ios - 按字典中的时间戳对 TableView 进行排序

swift - SpriteKit 中的方向键

javascript - "node filename.js"在 VS Code 中不起作用

javascript - 找不到变量 : URLSearchParams

ios - 如何使用 swift 比较核心数据中同一实体的两个属性值

javascript - 当用户按下主页按钮时,WebView 中的 Html 页面不会触发 'visibilitychange' 事件(iOS 8)

javascript - Phaser、Tileset 和 Tilemap 透明度