因此,我们遇到了一些问题,人们无法通过我们的应用收到推送通知。
我们发现,当用户删除并重新安装应用程序,同时向我们提供另一个推送权限时,它会在 _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/